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
server-ts: Fix getContent in updateNoteData
Elian Dorana354b54a0864
diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.tsindex 4f2c089bd5..4f2113f2e6 100644--- a/src/becca/entities/rows.ts+++ b/src/becca/entities/rows.ts@@ -5,7 +5,7 @@ export interface AttachmentRow {ownerId?: string;role: string;mime: string;- title?: string;+ title: string;position?: number;blobId?: string;isProtected?: boolean;diff --git a/src/services/notes.ts b/src/services/notes.tsindex 6449081ebf..d6efbf31b6 100644--- a/src/services/notes.ts+++ b/src/services/notes.ts@@ -744,7 +744,7 @@ function saveRevisionIfNeeded(note: BNote) {}}-function updateNoteData(noteId: string, content: string, attachments: BAttachment[] = []) {+function updateNoteData(noteId: string, content: string, attachments: AttachmentRow[] = []) {const note = becca.getNote(noteId);if (!note || !note.isContentAvailable()) {@@ -760,11 +760,7 @@ function updateNoteData(noteId: string, content: string, attachments: BAttachmenif (attachments?.length > 0) {const existingAttachmentsByTitle = utils.toMap(note.getAttachments({includeContentLength: false}), 'title');- for (const attachment of attachments) {- // TODO: The content property was extracted directly instead of `getContent`. To investigate.- const {attachmentId, role, mime, title, position} = attachment;- const content = attachment.getContent();-+ for (const {attachmentId, role, mime, title, position, content} of attachments) {if (attachmentId || !(title in existingAttachmentsByTitle)) {note.saveAttachment({attachmentId, role, mime, title, content, position});} else {@@ -772,7 +768,9 @@ function updateNoteData(noteId: string, content: string, attachments: BAttachmenexistingAttachment.role = role;existingAttachment.mime = mime;existingAttachment.position = position;- existingAttachment.setContent(content, {forceSave: true});+ if (content) {+ existingAttachment.setContent(content, {forceSave: true});+ }}}}