From 5a4803c48823f64681219d431db1583c2b1a7dd2 Mon Sep 17 00:00:00 2001 From: shermangriffiths Date: Wed, 17 Jul 2024 20:16:52 -0500 Subject: [PATCH] Undo recent addition of a filename hashing system in the core `Client` class functionality --- n2y/notion.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/n2y/notion.py b/n2y/notion.py index 9b1d023..c61e78b 100644 --- a/n2y/notion.py +++ b/n2y/notion.py @@ -1,4 +1,3 @@ -import hashlib import importlib.util import json from os import makedirs, path @@ -461,27 +460,21 @@ def _parse_response(self, response, stream=False): raise HTTPResponseError(error.response) return response.json() if not stream else response.content - def download_file(self, url, page, block_id=None): + def download_file(self, url, page, block_id): """ Download a file from a given URL into the MEDIA_ROOT. - Preserve the file extension from the URL, but use the - id of the block followed by an md5 hash. + Preserve the file extension from the URL, but use the page title + followed by a segment of the id of the block as the file name. """ - # block_id will be None if the file is not attached to a block - # (as is the case for page properties) or one would rather tie - # the file name to it's content than it's location in Notion. url_path = path.basename(urlparse(url).path) _, extension = path.splitext(url_path) content = self._get_url(url, stream=True) return self.save_file(content, page, extension, block_id) - def save_file(self, content, page, extension, block_id=None): - if block_id is None: - id_chars = hashlib.md5(content).hexdigest() - else: - id_chars = strip_hyphens(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}" full_filepath = path.join(self.media_root, relative_filepath)