Skip to content

Commit

Permalink
Prevent image collisions by using the full image id (#199)
Browse files Browse the repository at this point in the history
* Prevent image collisions by using the full image id

* Update tests
  • Loading branch information
sHermanGriffiths authored Sep 24, 2024
1 parent 26e0938 commit 52cc2b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion n2y/notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def download_file(self, url, page, block_id):
def save_file(self, content, page, extension, block_id):
id_chars = strip_hyphens(block_id)
page_title = sanitize_filename(page.title.to_plain_text())
relative_filepath = f"{page_title}-{id_chars[:11]}{extension}"
relative_filepath = f"{page_title}-{id_chars}{extension}"
full_filepath = path.join(self.media_root, relative_filepath)
makedirs(self.media_root, exist_ok=True)
with open(full_filepath, "wb") as temp_file:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,16 @@ def test_all_blocks_page_to_markdown(tmpdir):
# TODO: Add assertions about audio blocks and video blocks

# the word "caption" is bolded
assert "![Image **caption**](media/All_Blocks_Test_Page-5f1b0813453.jpeg)" in lines
assert (
"![Image"
" **caption**](media/All_Blocks_Test_Page-5f1b0813453c4e56969ba81443163dd3.jpeg)"
in lines
)

# from a file block in the Notion page
assert os.path.exists(tmpdir / "media" / "All_Blocks_Test_Page-5f1b0813453.jpeg")
assert os.path.exists(
tmpdir / "media" / "All_Blocks_Test_Page-5f1b0813453c4e56969ba81443163dd3.jpeg"
)


def test_page_in_database_to_markdown(tmpdir):
Expand Down

0 comments on commit 52cc2b2

Please sign in to comment.