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 protecting attachments
zadam83f19c05373f
diff --git a/package-lock.json b/package-lock.jsonindex d8512b3bc1..2b340a0134 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "trilium",- "version": "0.61.5-beta",+ "version": "0.61.6-beta","lockfileVersion": 2,"requires": true,"packages": {"": {"name": "trilium",- "version": "0.61.5-beta",+ "version": "0.61.6-beta","hasInstallScript": true,"license": "AGPL-3.0-only","dependencies": {diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.jsindex 9da0835f92..7108545c74 100644--- a/src/becca/entities/battachment.js+++ b/src/becca/entities/battachment.js@@ -98,7 +98,12 @@ class BAttachment extends AbstractBeccaEntity {}decrypt() {- if (this.isProtected && !this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) {+ if (!this.isProtected || !this.attachmentId) {+ this.isDecrypted = true;+ return;+ }++ if (!this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) {try {this.title = protectedSessionService.decryptString(this.title);this.isDecrypted = true;diff --git a/src/services/revisions.js b/src/services/revisions.jsindex 0a61643be5..e833a3bf53 100644--- a/src/services/revisions.js+++ b/src/services/revisions.js@@ -14,21 +14,34 @@ function protectRevisions(note) {}for (const revision of note.getRevisions()) {- if (note.isProtected === revision.isProtected) {- continue;- }+ if (note.isProtected !== revision.isProtected) {+ try {+ const content = revision.getContent();++ revision.isProtected = note.isProtected;- try {- const content = revision.getContent();+ // this will force de/encryption+ revision.setContent(content, {forceSave: true});+ } catch (e) {+ log.error(`Could not un/protect note revision '${revision.revisionId}'`);++ throw e;+ }+ }- revision.isProtected = note.isProtected;+ for (const attachment of revision.getAttachments()) {+ if (note.isProtected !== attachment.isProtected) {+ try {+ const content = attachment.getContent();- // this will force de/encryption- revision.setContent(content, {forceSave: true});- } catch (e) {- log.error(`Could not un/protect note revision '${revision.revisionId}'`);+ attachment.isProtected = note.isProtected;+ attachment.setContent(content, {forceSave: true});+ } catch (e) {+ log.error(`Could not un/protect attachment '${attachment.attachmentId}'`);- throw e;+ throw e;+ }+ }}}}