|
1 | 1 | """Nextcloud API for working with drop-down file's menu.""" |
2 | 2 |
|
3 | 3 | import dataclasses |
4 | | -import datetime |
5 | | -import os |
6 | | - |
7 | | -from pydantic import BaseModel |
8 | 4 |
|
9 | 5 | from ..._exceptions import NextcloudExceptionNotFound |
10 | 6 | from ..._misc import require_capabilities |
11 | 7 | from ..._session import AsyncNcSessionApp, NcSessionApp |
12 | | -from ...files import FsNode, permissions_to_str |
13 | 8 |
|
14 | 9 |
|
15 | 10 | @dataclasses.dataclass |
@@ -63,61 +58,6 @@ def __repr__(self): |
63 | 58 | return f"<{self.__class__.__name__} name={self.name}, mime={self.mime}, handler={self.action_handler}>" |
64 | 59 |
|
65 | 60 |
|
66 | | -class UiActionFileInfo(BaseModel): |
67 | | - """File Information Nextcloud sends to the External Application.""" |
68 | | - |
69 | | - fileId: int |
70 | | - """FileID without Nextcloud instance ID""" |
71 | | - name: str |
72 | | - """Name of the file/directory""" |
73 | | - directory: str |
74 | | - """Directory relative to the user's home directory""" |
75 | | - etag: str |
76 | | - mime: str |
77 | | - fileType: str |
78 | | - """**file** or **dir**""" |
79 | | - size: int |
80 | | - """size of file/directory""" |
81 | | - favorite: str |
82 | | - """**true** or **false**""" |
83 | | - permissions: int |
84 | | - """Combination of :py:class:`~nc_py_api.files.FilePermissions` values""" |
85 | | - mtime: int |
86 | | - """Last modified time""" |
87 | | - userId: str |
88 | | - """The ID of the user performing the action.""" |
89 | | - shareOwner: str | None |
90 | | - """If the object is shared, this is a display name of the share owner.""" |
91 | | - shareOwnerId: str | None |
92 | | - """If the object is shared, this is the owner ID of the share.""" |
93 | | - instanceId: str | None |
94 | | - """Nextcloud instance ID.""" |
95 | | - |
96 | | - def to_fs_node(self) -> FsNode: |
97 | | - """Returns usual :py:class:`~nc_py_api.files.FsNode` created from this class.""" |
98 | | - user_path = os.path.join(self.directory, self.name).rstrip("/") |
99 | | - is_dir = bool(self.fileType.lower() == "dir") |
100 | | - if is_dir: |
101 | | - user_path += "/" |
102 | | - full_path = os.path.join(f"files/{self.userId}", user_path.lstrip("/")) |
103 | | - file_id = str(self.fileId).rjust(8, "0") |
104 | | - |
105 | | - permissions = "S" if self.shareOwnerId else "" |
106 | | - permissions += permissions_to_str(self.permissions, is_dir) |
107 | | - return FsNode( |
108 | | - full_path, |
109 | | - etag=self.etag, |
110 | | - size=self.size, |
111 | | - content_length=0 if is_dir else self.size, |
112 | | - permissions=permissions, |
113 | | - favorite=bool(self.favorite.lower() == "true"), |
114 | | - file_id=file_id + self.instanceId if self.instanceId else file_id, |
115 | | - fileid=self.fileId, |
116 | | - last_modified=datetime.datetime.utcfromtimestamp(self.mtime).replace(tzinfo=datetime.timezone.utc), |
117 | | - mimetype=self.mime, |
118 | | - ) |
119 | | - |
120 | | - |
121 | 61 | class _UiFilesActionsAPI: |
122 | 62 | """API for the drop-down menu in Nextcloud **Files app**, avalaible as **nc.ui.files_dropdown_menu.<method>**.""" |
123 | 63 |
|
|
0 commit comments