1010from ..._session import NcSessionApp
1111from ...files import FilePermissions , FsNode
1212
13- ENDPOINT_SUFFIX = "files/actions/menu"
14-
1513
1614class UiActionFileInfo (BaseModel ):
1715 """File Information Nextcloud sends to the External Application."""
@@ -40,18 +38,17 @@ class UiActionFileInfo(BaseModel):
4038 """If the object is shared, this is a display name of the share owner."""
4139 shareOwnerId : typing .Optional [str ]
4240 """If the object is shared, this is the owner ID of the share."""
41+ instanceId : typing .Optional [str ]
42+ """Nextcloud instance ID."""
4343
4444 def to_fs_node (self ) -> FsNode :
45- """Returns created ``FsNode`` from the file info given.
46-
47- .. note:: :py:attr:`~nc_py_api.files.FsNode.file_id` in this case is ``without`` **instance_id**
48- and equal to :py:attr:`~nc_py_api.files.FsNodeInfo.fileid`.
49- """
45+ """Returns usual :py:class:`~nc_py_api.files.FsNode` created from this class."""
5046 user_path = os .path .join (self .directory , self .name ).rstrip ("/" )
5147 is_dir = bool (self .fileType .lower () == "dir" )
5248 if is_dir :
5349 user_path += "/"
5450 full_path = os .path .join (f"files/{ self .userId } " , user_path .lstrip ("/" ))
51+ file_id = str (self .fileId ).rjust (8 , "0" )
5552
5653 permissions = "S" if self .shareOwnerId else ""
5754 if self .permissions & FilePermissions .PERMISSION_SHARE :
@@ -71,7 +68,7 @@ def to_fs_node(self) -> FsNode:
7168 content_length = 0 if is_dir else self .size ,
7269 permissions = permissions ,
7370 favorite = bool (self .favorite .lower () == "true" ),
74- file_id = self .fileId ,
71+ file_id = file_id + self .instanceId if self . instanceId else file_id ,
7572 fileid = self .fileId ,
7673 last_modified = datetime .utcfromtimestamp (self .mtime ).replace (tzinfo = timezone .utc ),
7774 )
@@ -91,6 +88,8 @@ class UiFileActionHandlerInfo(BaseModel):
9188class _UiFilesActionsAPI :
9289 """API for the drop-down menu in Nextcloud **Files app**."""
9390
91+ _ep_suffix : str = "files/actions/menu"
92+
9493 def __init__ (self , session : NcSessionApp ):
9594 self ._session = session
9695
@@ -109,14 +108,14 @@ def register(self, name: str, display_name: str, callback_url: str, **kwargs) ->
109108 "action_handler" : callback_url ,
110109 },
111110 }
112- self ._session .ocs (method = "POST" , path = f"{ self ._session .ae_url } /{ ENDPOINT_SUFFIX } " , json = params )
111+ self ._session .ocs (method = "POST" , path = f"{ self ._session .ae_url } /{ self . _ep_suffix } " , json = params )
113112
114113 def unregister (self , name : str , not_fail = True ) -> None :
115114 """Removes files dropdown menu element."""
116115 require_capabilities ("app_ecosystem_v2" , self ._session .capabilities )
117116 params = {"fileActionMenuName" : name }
118117 try :
119- self ._session .ocs (method = "DELETE" , path = f"{ self ._session .ae_url } /{ ENDPOINT_SUFFIX } " , json = params )
118+ self ._session .ocs (method = "DELETE" , path = f"{ self ._session .ae_url } /{ self . _ep_suffix } " , json = params )
120119 except NextcloudExceptionNotFound as e :
121120 if not not_fail :
122121 raise e from None
0 commit comments