Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test: pin why mermaid/mindMap need no orphan-erasure exemption
Elian Doranf7bad961592f
diff --git a/apps/server/src/services/notes.spec.ts b/apps/server/src/services/notes.spec.tsindex 57944bd5a0..4ab6a21426 100644--- a/apps/server/src/services/notes.spec.ts+++ b/apps/server/src/services/notes.spec.ts@@ -421,6 +421,26 @@ describe("saveLinks", () => {return attr;}+ // `checkImageAttachments` exempts the canvas and spreadsheet rendered images by title, but not+ // the mermaid and mindMap ones. That looks like an oversight until you notice `saveLinks` bails+ // out before it for those two types, so their SVGs are never reachable by orphan erasure at all.+ // Pinned here: if either type ever gains a `saveLinks` branch, it needs an exemption first, and+ // this test is what will say so.+ it.each([+ [ "mermaid", "text/mermaid", "mermaid-export.svg", "flowchart TD\n A --> B" ],+ [ "mindMap", "application/json", "mindmap-export.svg", `{"nodeData":{}}` ]+ ] as const)("never schedules the %s rendered image for erasure, though nothing references it", (type, mime, title, content) => {+ const note = buildNote({ title: "Diagram", type, mime, attachments: [{ title, role: "image", mime: "image/svg+xml" }] });+ mockAttachmentSaves(note);+ const [rendered] = note.getAttachments();++ // The content never mentions the attachment — for a text note this would schedule erasure.+ saveLinks(note, content);++ expect(rendered.save).not.toHaveBeenCalled();+ expect(rendered.utcDateScheduledForErasureSince).toBeFalsy();+ });+it("does not delete existing imageLink relations on markdown notes that reference images", () => {const note = buildNote({ title: "Test", type: "code", mime: "text/x-markdown" });const targetNote = buildNote({ title: "Image Note", type: "image" });diff --git a/packages/trilium-core/src/services/export/zip.ts b/packages/trilium-core/src/services/export/zip.tsindex b10f7eb7bd..daa978528c 100644--- a/packages/trilium-core/src/services/export/zip.ts+++ b/packages/trilium-core/src/services/export/zip.ts@@ -254,9 +254,12 @@ async function exportToZip(taskContext: TaskContext<"export">, branch: BBranch,* own HTML page in a share export, and renders as a broken image.*/function getEmbeddedImageUrl(targetNoteId: string, sourceMeta: NoteMeta): string | null {+ // `targetMeta` is undefined when the embedded note lies outside the exported subtree. It is+ // typed as always present, so guard it explicitly rather than leaning on `attachmentTitle`+ // happening to be undefined in that case.const targetMeta = noteIdToMeta[targetNoteId];const attachmentTitle = getImageAttachmentTitle(targetMeta?.type);- const attachmentMeta = attachmentTitle+ const attachmentMeta = targetMeta && attachmentTitle? (targetMeta.attachments || []).find((attMeta) => attMeta.title === attachmentTitle): undefined;