From de0051a31c49a7a268ac1542d118111ed2b04191 Mon Sep 17 00:00:00 2001 From: sashacmc Date: Wed, 5 Jun 2024 01:29:13 +0200 Subject: [PATCH] Fix file upload --- notion/block.py | 22 +++++++++++++++------- notion/settings.py | 6 +++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/notion/block.py b/notion/block.py index 572f945c..960a3fc9 100644 --- a/notion/block.py +++ b/notion/block.py @@ -685,19 +685,27 @@ def upload_file(self, path): data = self._client.post( "getUploadFileUrl", - {"bucket": "secure", "name": filename, "contentType": mimetype}, + { + "bucket": "secure", + "name": filename, + "contentType": mimetype, + "record": { + "table": "block", + "id": self.id, + "spaceId": self.space_info["spaceId"], + }, + }, ).json() with open(path, "rb") as f: - response = requests.put( - data["signedPutUrl"], data=f, headers={"Content-type": mimetype} - ) + response = requests.put(data["signedPutUrl"], data=f, headers={"Content-type": mimetype}) response.raise_for_status() self.display_source = data["url"] self.source = data["url"] - self.file_id = data["url"][len(S3_URL_PREFIX) :].split("/")[0] + self.file_id = data["url"][len(S3_URL_PREFIX) :].split("/")[1] + return data class VideoBlock(EmbedOrUploadBlock): @@ -759,7 +767,7 @@ class CollectionViewBlock(MediaBlock): @property def collection(self): - collection_id = self.get("collection_id") + collection_id = self.get("format.collection_pointer.id") if not collection_id: return None if not hasattr(self, "_collection"): @@ -770,7 +778,7 @@ def collection(self): def collection(self, val): if hasattr(self, "_collection"): del self._collection - self.set("collection_id", val.id) + self.set("format.collection_pointer.id", val.id) @property def views(self): diff --git a/notion/settings.py b/notion/settings.py index 3878f19b..ab3f4ac3 100644 --- a/notion/settings.py +++ b/notion/settings.py @@ -3,9 +3,9 @@ BASE_URL = "https://www.notion.so/" API_BASE_URL = BASE_URL + "api/v3/" -SIGNED_URL_PREFIX = "https://www.notion.so/signed/" -S3_URL_PREFIX = "https://s3-us-west-2.amazonaws.com/secure.notion-static.com/" -S3_URL_PREFIX_ENCODED = "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/" +SIGNED_URL_PREFIX = "https://file.notion.so/f/f/" +S3_URL_PREFIX = "https://prod-files-secure.s3.us-west-2.amazonaws.com/" +S3_URL_PREFIX_ENCODED = "https://prod-files-secure.s3.us-west-2.amazonaws.com/" DATA_DIR = os.environ.get( "NOTION_DATA_DIR", str(Path(os.path.expanduser("~")).joinpath(".notion-py")) )