diff --git a/client/views/Note.vue b/client/views/Note.vue index a95c675c..2a63ea51 100644 --- a/client/views/Note.vue +++ b/client/views/Note.vue @@ -161,7 +161,7 @@ const isDraftModalVisible = ref(false); const isNewNote = computed(() => !props.title); const loadingIndicator = ref(); const note = ref({}); -const reservedFilenameCharacters = /[<>:"/\\|?*]/; +const reservedFilenameCharacters = /[<>:"\\|?*]/; const router = useRouter(); const newTitle = ref(); const toast = useToast(); diff --git a/server/helpers.py b/server/helpers.py index 367830b5..958995e5 100644 --- a/server/helpers.py +++ b/server/helpers.py @@ -16,7 +16,7 @@ def camel_case(snake_case_str: str) -> str: def is_valid_filename(value): """Raise ValueError if the declared string contains any of the following characters: <>:"/\\|?*""" - invalid_chars = r'<>:"/\|?*' + invalid_chars = r'<>:"\|?*' if any(invalid_char in value for invalid_char in invalid_chars): raise ValueError( "title cannot include any of the following characters: " diff --git a/server/main.py b/server/main.py index 1cc0701f..546f22ca 100644 --- a/server/main.py +++ b/server/main.py @@ -32,7 +32,7 @@ @router.get("/login", include_in_schema=False) @router.get("/search", include_in_schema=False) @router.get("/new", include_in_schema=False) -@router.get("/note/{title}", include_in_schema=False) +@router.get("/note/{title:path}", include_in_schema=False) def root(title: str = ""): with open("client/dist/index.html", "r", encoding="utf-8") as f: html = f.read() @@ -61,7 +61,7 @@ def token(data: Login): # region Notes # Get Note @router.get( - "/api/notes/{title}", + "/api/notes/{title:path}", dependencies=auth_deps, response_model=Note, ) diff --git a/server/notes/file_system/file_system.py b/server/notes/file_system/file_system.py index 656c2079..e181ee2b 100644 --- a/server/notes/file_system/file_system.py +++ b/server/notes/file_system/file_system.py @@ -225,9 +225,9 @@ def _add_note_to_index( def _list_all_note_filenames(self) -> List[str]: """Return a list of all note filenames.""" return [ - os.path.split(filepath)[1] + os.path.relpath(filepath, self.storage_path) for filepath in glob.glob( - os.path.join(self.storage_path, "*" + MARKDOWN_EXT) + os.path.join(self.storage_path, "**/*" + MARKDOWN_EXT), recursive = True ) ] @@ -390,5 +390,7 @@ def _read_file(filepath: str): @staticmethod def _write_file(filepath: str, content: str, overwrite: bool = False): logger.debug(f"Writing to '{filepath}'") + directory = os.path.dirname(filepath) + os.makedirs(directory, exist_ok = True) with open(filepath, "w" if overwrite else "x") as f: f.write(content)