Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions notion/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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"):
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions notion/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)
Expand Down