diff --git a/src/becca/entities/bnote_attachment.js b/src/becca/entities/bnote_attachment.js index 5ec9cddab..e72faaf6a 100644 --- a/src/becca/entities/bnote_attachment.js +++ b/src/becca/entities/bnote_attachment.js @@ -22,8 +22,16 @@ class BNoteAttachment extends AbstractBeccaEntity { constructor(row) { super(); - /** @type {string} */ - this.noteAttachmentId = row.noteAttachmentId; + if (!row.noteId) { + throw new Error("'noteId' must be given to initialize a NoteAttachment entity"); + } + + if (!row.name) { + throw new Error("'name' must be given to initialize a NoteAttachment entity"); + } + + /** @type {string} needs to be set at the initialization time since it's used in the .setContent() */ + this.noteAttachmentId = row.noteAttachmentId || `${this.noteId}_${this.name}`; /** @type {string} */ this.noteId = row.noteId; /** @type {string} */ @@ -82,6 +90,9 @@ class BNoteAttachment extends AbstractBeccaEntity { } setContent(content) { + this.contentCheckSum = this.calculateCheckSum(content); + this.save(); + const pojo = { noteAttachmentId: this.noteAttachmentId, content: content, @@ -99,14 +110,12 @@ class BNoteAttachment extends AbstractBeccaEntity { sql.upsert("note_attachment_contents", "noteAttachmentId", pojo); - this.contentCheckSum = this.calculateCheckSum(pojo.content); - entityChangesService.addEntityChange({ entityName: 'note_attachment_contents', entityId: this.noteAttachmentId, hash: this.contentCheckSum, isErased: false, - utcDateChanged: this.getUtcDateChanged(), + utcDateChanged: pojo.utcDateModified, isSynced: true }); } @@ -134,6 +143,7 @@ class BNoteAttachment extends AbstractBeccaEntity { name: this.name, mime: this.mime, isProtected: !!this.isProtected, + contentCheckSum: this.contentCheckSum, isDeleted: false, utcDateModified: this.utcDateModified, content: this.content, diff --git a/src/public/app/widgets/mermaid.js b/src/public/app/widgets/mermaid.js index ad8e94eb8..b4aa7f4f7 100644 --- a/src/public/app/widgets/mermaid.js +++ b/src/public/app/widgets/mermaid.js @@ -1,6 +1,7 @@ import libraryLoader from "../services/library_loader.js"; import NoteContextAwareWidget from "./note_context_aware_widget.js"; import froca from "../services/froca.js"; +import server from "../services/server.js"; const TPL = `