common: fix notes with empty title exporting with empty filename (fixes #6088)

This commit is contained in:
Abdullah Atta
2024-09-10 09:36:55 +05:00
parent 2293866c61
commit 4040f2ecc4

View File

@@ -67,9 +67,9 @@ export async function* exportNotes(
const notePathMap: Map<string, string[]> = new Map(); const notePathMap: Map<string, string[]> = new Map();
for await (const note of notes.fields(["notes.id", "notes.title"])) { for await (const note of notes.fields(["notes.id", "notes.title"])) {
const filename = `${sanitizeFilename(note.title, { replacement: "-" })}.${ const filename = `${sanitizeFilename(note.title || "Untitled", {
FORMAT_TO_EXT[format] replacement: "-"
}`; })}.${FORMAT_TO_EXT[format]}`;
const notebooks = await database.relations const notebooks = await database.relations
.to({ id: note.id, type: "note" }, "notebook") .to({ id: note.id, type: "note" }, "notebook")
.get(); .get();
@@ -161,7 +161,9 @@ export async function* exportNote(
return; return;
const attachmentsRoot = "attachments"; const attachmentsRoot = "attachments";
const filename = sanitizeFilename(note.title, { replacement: "-" }); const filename = sanitizeFilename(note.title || "Untitled", {
replacement: "-"
});
const ext = FORMAT_TO_EXT[options.format]; const ext = FORMAT_TO_EXT[options.format];
const path = [filename, ext].join("."); const path = [filename, ext].join(".");
const pendingAttachments: Map<string, Attachment> = new Map(); const pendingAttachments: Map<string, Attachment> = new Map();
@@ -194,7 +196,9 @@ export async function* exportNote(
} }
} catch (e) { } catch (e) {
yield new Error( yield new Error(
`Failed to export note "${note.title}": ${(e as Error).message}` `Failed to export note "${note.title || "<Untitled>"}": ${
(e as Error).message
}`
); );
} }
} }
@@ -227,7 +231,9 @@ export async function exportContent(
!database.vault.unlocked && !database.vault.unlocked &&
!(await unlockVault?.()) !(await unlockVault?.())
) { ) {
throw new Error(`Could not export locked note: "${note.title}".`); throw new Error(
`Could not export locked note: "${note.title || "<Untitled>"}".`
);
} }
const contentItem = rawContent?.locked const contentItem = rawContent?.locked