From 37dcba7b33b5c996b0d3e9f7c3406293f0a21d33 Mon Sep 17 00:00:00 2001 From: Kyle Wenholz Date: Tue, 27 Dec 2022 11:41:26 -0800 Subject: [PATCH] Use drivewsid and zone that work for app folders Appears to be backwards compatible with everything. --- pyicloud/services/drive.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pyicloud/services/drive.py b/pyicloud/services/drive.py index 87573ce6..03529daf 100644 --- a/pyicloud/services/drive.py +++ b/pyicloud/services/drive.py @@ -42,7 +42,7 @@ def get_node_data(self, node_id): data=json.dumps( [ { - "drivewsid": "FOLDER::com.apple.CloudDocs::%s" % node_id, + "drivewsid": node_id, "partialData": False, } ] @@ -51,12 +51,12 @@ def get_node_data(self, node_id): self._raise_if_error(request) return request.json()[0] - def get_file(self, file_id, **kwargs): + def get_file(self, file_id, zone, **kwargs): """Returns iCloud Drive file.""" file_params = dict(self.params) file_params.update({"document_id": file_id}) response = self.session.get( - self._document_root + "/ws/com.apple.CloudDocs/download/by_id", + self._document_root + ("/ws/%s/download/by_id" % zone), params=file_params, ) self._raise_if_error(response) @@ -72,7 +72,8 @@ def get_file(self, file_id, **kwargs): def get_app_data(self): """Returns the app library (previously ubiquity).""" request = self.session.get( - self._service_root + "/retrieveAppLibraries", params=self.params + self._service_root + "/retrieveAppLibraries", + params=self.params ) self._raise_if_error(request) return request.json()["items"] @@ -220,7 +221,7 @@ def move_items_to_trash(self, node_id, etag): def root(self): """Returns the root node.""" if not self._root: - self._root = DriveNode(self, self.get_node_data("root")) + self._root = DriveNode(self, self.get_node_data("FOLDER::com.apple.CloudDocs::root")) return self._root def __getattr__(self, attr): @@ -263,7 +264,7 @@ def get_children(self): """Gets the node children.""" if not self._children: if "items" not in self.data: - self.data.update(self.connection.get_node_data(self.data["docwsid"])) + self.data.update(self.connection.get_node_data(self.data["drivewsid"])) if "items" not in self.data: raise KeyError("No items in folder, status: %s" % self.data["status"]) self._children = [ @@ -302,11 +303,11 @@ def open(self, **kwargs): response = Response() response.raw = io.BytesIO() return response - return self.connection.get_file(self.data["docwsid"], **kwargs) + return self.connection.get_file(self.data["docwsid"], self.data["zone"], **kwargs) def upload(self, file_object, **kwargs): """Upload a new file.""" - return self.connection.send_file(self.data["docwsid"], file_object, **kwargs) + return self.connection.send_file(self.data["drivewsid"], file_object, **kwargs) def dir(self): """Gets the node list of directories."""