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(server/share): attachment links
Elian Doran614a8f177c9f
diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.tsindex 137d85c97e..c8601fe57c 100644--- a/apps/server/src/share/content_renderer.spec.ts+++ b/apps/server/src/share/content_renderer.spec.ts@@ -21,12 +21,35 @@ describe("content_renderer", () => {Welcome to Trilium Notes!</strong></p>`;+ const note = buildShareNote({ content });+ const result = getContent(note);+ expect(result.content).toStrictEqual(content);+ });++ it("handles attachment link", () => {+ const content = trimIndentation`\+ <h1>Test</h1>+ <p>+ <a class="reference-link" href="#root/iwTmeWnqBG5Q?viewMode=attachments&attachmentId=q14s2Id7V6pp">+ 5863845791835102555.mp4+ </a>+ + </p>+ `;const note = buildShareNote({- title: "Note",- content+ content,+ attachments: [ { id: "q14s2Id7V6pp" } ]});const result = getContent(note);- expect(result.content).toStrictEqual(content);+ expect(result.content).toStrictEqual(trimIndentation`\+ <h1>Test</h1>+ <p>+ <a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download">+ 5863845791835102555.mp4+ </a>+ + </p>+ `);});it("renders included notes", () => {diff --git a/apps/server/src/test/shaca_mocking.ts b/apps/server/src/test/shaca_mocking.tsindex af02394a04..8b2068a0ec 100644--- a/apps/server/src/test/shaca_mocking.ts+++ b/apps/server/src/test/shaca_mocking.ts@@ -1,4 +1,5 @@import utils from "../services/utils.js";+import SAttachment from "../share/shaca/entities/sattachment.js";import SAttribute from "../share/shaca/entities/sattribute.js";import SNote from "../share/shaca/entities/snote.js";import shaca from "../share/shaca/shaca.js";@@ -6,11 +7,19 @@ import shaca from "../share/shaca/shaca.js";type AttributeDefinitions = { [key in `#${string}`]: string; };type RelationDefinitions = { [key in `~${string}`]: string; };+interface AttachementDefinition {+ id?: string;+ role?: string;+ mime?: string;+ title?: string;+}+interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {id?: string | undefined;title?: string;content?: string | Buffer<ArrayBufferLike>;children?: NoteDefinition[];+ attachments?: AttachementDefinition[];isProtected?: boolean;}@@ -60,6 +69,21 @@ export function buildShareNote(noteDef: NoteDefinition) {};}+ // Handle attachments.+ if (noteDef.attachments) {+ for (const attachmentDef of noteDef.attachments) {+ new SAttachment([+ attachmentDef.id ?? utils.randomString(12),+ note.noteId,+ attachmentDef.role ?? "file",+ attachmentDef.mime ?? "application/blob",+ attachmentDef.title ?? "New attachment",+ blobId,+ new Date().toUTCString(), // utcDateModified+ ]);+ }+ }+// Handle children.if (noteDef.children) {for (const childDef of noteDef.children) {