mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Fix getContent in updateNoteData
This commit is contained in:
parent
b84b27692c
commit
a354b54a08
@ -5,7 +5,7 @@ export interface AttachmentRow {
|
|||||||
ownerId?: string;
|
ownerId?: string;
|
||||||
role: string;
|
role: string;
|
||||||
mime: string;
|
mime: string;
|
||||||
title?: string;
|
title: string;
|
||||||
position?: number;
|
position?: number;
|
||||||
blobId?: string;
|
blobId?: string;
|
||||||
isProtected?: boolean;
|
isProtected?: boolean;
|
||||||
|
@ -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);
|
const note = becca.getNote(noteId);
|
||||||
|
|
||||||
if (!note || !note.isContentAvailable()) {
|
if (!note || !note.isContentAvailable()) {
|
||||||
@ -760,11 +760,7 @@ function updateNoteData(noteId: string, content: string, attachments: BAttachmen
|
|||||||
if (attachments?.length > 0) {
|
if (attachments?.length > 0) {
|
||||||
const existingAttachmentsByTitle = utils.toMap(note.getAttachments({includeContentLength: false}), 'title');
|
const existingAttachmentsByTitle = utils.toMap(note.getAttachments({includeContentLength: false}), 'title');
|
||||||
|
|
||||||
for (const attachment of attachments) {
|
for (const {attachmentId, role, mime, title, position, content} 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();
|
|
||||||
|
|
||||||
if (attachmentId || !(title in existingAttachmentsByTitle)) {
|
if (attachmentId || !(title in existingAttachmentsByTitle)) {
|
||||||
note.saveAttachment({attachmentId, role, mime, title, content, position});
|
note.saveAttachment({attachmentId, role, mime, title, content, position});
|
||||||
} else {
|
} else {
|
||||||
@ -772,7 +768,9 @@ function updateNoteData(noteId: string, content: string, attachments: BAttachmen
|
|||||||
existingAttachment.role = role;
|
existingAttachment.role = role;
|
||||||
existingAttachment.mime = mime;
|
existingAttachment.mime = mime;
|
||||||
existingAttachment.position = position;
|
existingAttachment.position = position;
|
||||||
existingAttachment.setContent(content, {forceSave: true});
|
if (content) {
|
||||||
|
existingAttachment.setContent(content, {forceSave: true});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user