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
fix creating revisions for non-text notes #4176
zadama749e241478a
diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.jsindex 9f344279d3..1f05b4001f 100644--- a/src/becca/entities/bnote.js+++ b/src/becca/entities/bnote.js@@ -1624,10 +1624,10 @@ class BNote extends AbstractBeccaEntity {noteContent = noteContent.replaceAll(new RegExp(`href="[^"]*attachmentId=${noteAttachment.attachmentId}[^"]*"`, 'gi'),`href="api/attachments/${revisionAttachment.attachmentId}/download"`);}-- revision.setContent(noteContent, {forceSave: true});}+ revision.setContent(noteContent);+return revision;});}diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 768efaeb65..5a7c2d8a81 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -12,6 +12,7 @@ const BBranch = require('../becca/entities/bbranch');const revisionService = require('./revisions');const becca = require("../becca/becca");const utils = require("../services/utils");+const eraseService = require("../services/erase");const {sanitizeAttributeName} = require("./sanitize_attribute_name");const noteTypes = require("../services/note_types").getNoteTypeNames();@@ -440,7 +441,7 @@ class ConsistencyChecks {this.findAndFixIssues(`SELECT notes.noteId, notes.type, notes.mimeFROM notes- JOIN blobs USING (blobId)+ JOIN blobs USING (blobId)WHERE isDeleted = 0AND isProtected = 0AND content IS NULL`,@@ -460,19 +461,36 @@ class ConsistencyChecks {}this.findAndFixIssues(`- SELECT revisions.revisionId+ SELECT revisions.revisionId, blobs.blobIdFROM revisionsLEFT JOIN blobs USING (blobId)WHERE blobs.blobId IS NULL`,- ({revisionId}) => {+ ({revisionId, blobId}) => {if (this.autoFix) {revisionService.eraseRevisions([revisionId]);this.reloadNeeded = true;- logFix(`Note revision content '${revisionId}' was set to erased since its content did not exist.`);+ logFix(`Note revision '${revisionId}' was erased since the referenced blob '${blobId}' did not exist.`);} else {- logError(`Note revision content '${revisionId}' does not exist`);+ logError(`Note revision '${revisionId}' blob '${blobId}' does not exist`);+ }+ });++ this.findAndFixIssues(`+ SELECT attachments.attachmentId, blobs.blobId+ FROM attachments+ LEFT JOIN blobs USING (blobId)+ WHERE blobs.blobId IS NULL`,+ ({attachmentId, blobId}) => {+ if (this.autoFix) {+ eraseService.eraseAttachments([attachmentId]);++ this.reloadNeeded = true;++ logFix(`Attachment '${attachmentId}' was erased since the referenced blob '${blobId}' did not exist.`);+ } else {+ logError(`Attachment '${attachmentId}' blob '${blobId}' does not exist`);}});diff --git a/src/services/erase.js b/src/services/erase.jsindex e5e7628bfc..1fc03cc09e 100644--- a/src/services/erase.js+++ b/src/services/erase.js@@ -183,5 +183,6 @@ module.exports = {eraseDeletedNotesNow,eraseUnusedAttachmentsNow,eraseNotesWithDeleteId,- eraseUnusedBlobs+ eraseUnusedBlobs,+ eraseAttachments};diff --git a/src/services/revisions.js b/src/services/revisions.jsindex e833a3bf53..d7b059efa4 100644--- a/src/services/revisions.js+++ b/src/services/revisions.js@@ -51,7 +51,7 @@ function eraseRevisions(revisionIdsToErase) {return;}- log.info(`Removing note revisions: ${JSON.stringify(revisionIdsToErase)}`);+ log.info(`Removing revisions: ${JSON.stringify(revisionIdsToErase)}`);sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase);sql.executeMany(`UPDATE entity_changes SET isErased = 1, utcDateChanged = '${dateUtils.utcNowDateTime()}' WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase);