diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index 1f05b4001..6e02bf01c 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -1607,16 +1607,12 @@ class BNote extends AbstractBeccaEntity { revision.save(); // to generate revisionId, which is then used to save attachments - if (this.type === 'text') { - for (const noteAttachment of this.getAttachments()) { - if (noteAttachment.utcDateScheduledForErasureSince) { - continue; - } - - const revisionAttachment = noteAttachment.copy(); - revisionAttachment.ownerId = revision.revisionId; - revisionAttachment.setContent(noteAttachment.getContent(), {forceSave: true}); + for (const noteAttachment of this.getAttachments()) { + const revisionAttachment = noteAttachment.copy(); + revisionAttachment.ownerId = revision.revisionId; + revisionAttachment.setContent(noteAttachment.getContent(), {forceSave: true}); + if (this.type === 'text') { // content is rewritten to point to the revision attachments noteContent = noteContent.replaceAll(`attachments/${noteAttachment.attachmentId}`, `attachments/${revisionAttachment.attachmentId}`); diff --git a/src/becca/entities/brevision.js b/src/becca/entities/brevision.js index 2e0f1f33e..09a78db64 100644 --- a/src/becca/entities/brevision.js +++ b/src/becca/entities/brevision.js @@ -86,6 +86,29 @@ class BRevision extends AbstractBeccaEntity { return this._getContent(); } + /** + * @returns {*} + * @throws Error in case of invalid JSON */ + getJsonContent() { + const content = this.getContent(); + + if (!content || !content.trim()) { + return null; + } + + return JSON.parse(content); + } + + /** @returns {*|null} valid object or null if the content cannot be parsed as JSON */ + getJsonContentSafely() { + try { + return this.getJsonContent(); + } + catch (e) { + return null; + } + } + /** * @param content * @param {object} [opts] @@ -105,6 +128,45 @@ class BRevision extends AbstractBeccaEntity { .map(row => new BAttachment(row)); } + /** @returns {BAttachment|null} */ + getAttachmentById(attachmentId, opts = {}) { + opts.includeContentLength = !!opts.includeContentLength; + + const query = opts.includeContentLength + ? `SELECT attachments.*, LENGTH(blobs.content) AS contentLength + FROM attachments + JOIN blobs USING (blobId) + WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0` + : `SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`; + + return sql.getRows(query, [this.revisionId, attachmentId]) + .map(row => new BAttachment(row))[0]; + } + + /** @returns {BAttachment[]} */ + getAttachmentsByRole(role) { + return sql.getRows(` + SELECT attachments.* + FROM attachments + WHERE ownerId = ? + AND role = ? + AND isDeleted = 0 + ORDER BY position`, [this.revisionId, role]) + .map(row => new BAttachment(row)); + } + + /** @returns {BAttachment} */ + getAttachmentByTitle(title) { + return sql.getRows(` + SELECT attachments.* + FROM attachments + WHERE ownerId = ? + AND title = ? + AND isDeleted = 0 + ORDER BY position`, [this.revisionId, title]) + .map(row => new BAttachment(row))[0]; + } + beforeSaving() { super.beforeSaving(); diff --git a/src/public/app/widgets/dialogs/revisions.js b/src/public/app/widgets/dialogs/revisions.js index 1fa3eedc0..d5a56328c 100644 --- a/src/public/app/widgets/dialogs/revisions.js +++ b/src/public/app/widgets/dialogs/revisions.js @@ -274,26 +274,11 @@ export default class RevisionsDialog extends BasicWidget { this.$content.html($table); } else if (revisionItem.type === 'canvas') { - /** - * FIXME: We load a font called Virgil.wof2, which originates from excalidraw.com - * REMOVE external dependency!!!! This is defined in the svg in defs.style - */ - const content = fullRevision.content; + const sanitizedTitle = revisionItem.title.replace(/[^a-z0-9-.]/gi, ""); - try { - const data = JSON.parse(content) - const svg = data.svg || "no svg present." - - /** - * maxWidth: 100% use full width of container but do not enlarge! - * height:auto to ensure that height scales with width - */ - const $svgHtml = $(svg).css({maxWidth: "100%", height: "auto"}); - this.$content.html($('