Skip to content

Commit

Permalink
fix: filter out unsupported file extensions for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Apr 4, 2022
1 parent 807b04c commit e6e6fba
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions enex2notion/note_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def parse_note(

_resolve_resources(note_blocks, note)

_remove_banned_files(note_blocks, note)

return note_blocks


Expand All @@ -59,6 +61,24 @@ def _resolve_resources(note_blocks, note: EvernoteNote):
_resolve_resources(block.children, note)


def _remove_banned_files(note_blocks, note: EvernoteNote):
for block in note_blocks.copy():
if isinstance(block, NotionUploadableBlock):
if _is_banned_extension(block.resource.file_name):
logger.warning(
f"Cannot upload '{block.resource.file_name}' from '{note.title}',"
f" this file extensions is banned by Notion"
)
note_blocks.remove(block)
if block.children:
_remove_banned_files(block.children, note)


def _is_banned_extension(filename):
file_ext = filename.split(".")[-1]
return file_ext in ["exe", "com", "js"]


def _add_meta(note_blocks, note: EvernoteNote):
note_blocks.insert(
0,
Expand Down

0 comments on commit e6e6fba

Please sign in to comment.