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
added "update pojo" stage in entity saving to avoid encrypting data on protected note directly on the entity
azivneree1e4fc710bd
diff --git a/src/entities/attribute.js b/src/entities/attribute.jsindex a40964b9f2..85cf2c8a6b 100644--- a/src/entities/attribute.js+++ b/src/entities/attribute.js@@ -105,6 +105,11 @@ class Attribute extends Entity {this.dateModified = dateUtils.nowDate();}}++ // cannot be static!+ updatePojo(pojo) {+ delete pojo.isOwned;+ }}module.exports = Attribute;\ No newline at end of filediff --git a/src/entities/branch.js b/src/entities/branch.jsindex 6019fe99a4..96770e6c55 100644--- a/src/entities/branch.js+++ b/src/entities/branch.js@@ -59,6 +59,11 @@ class Branch extends Entity {this.dateModified = dateUtils.nowDate();}}++ // cannot be static!+ updatePojo(pojo) {+ delete pojo.origParentNoteId;+ }}module.exports = Branch;\ No newline at end of filediff --git a/src/entities/note.js b/src/entities/note.jsindex 64df89f760..cd7ec238a3 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -606,10 +606,6 @@ class Note extends Entity {// we do this here because encryption needs the note ID for the IVthis.generateIdIfNecessary();- if (this.isProtected) {- protectedSessionService.encryptNote(this);- }-if (!this.isDeleted) {this.isDeleted = false;}@@ -624,6 +620,17 @@ class Note extends Entity {this.dateModified = dateUtils.nowDate();}}++ // cannot be static!+ updatePojo(pojo) {+ if (pojo.isProtected) {+ protectedSessionService.encryptNote(pojo);+ }++ delete pojo.jsonContent;+ delete pojo.isContentAvailable;+ delete pojo.__attributeCache;+ }}module.exports = Note;\ No newline at end of filediff --git a/src/services/repository.js b/src/services/repository.jsindex a416050e59..7098a61427 100644--- a/src/services/repository.js+++ b/src/services/repository.js@@ -74,13 +74,13 @@ async function updateEntity(entity) {const clone = Object.assign({}, entity);- // transient properties not supposed to be persisted- delete clone.jsonContent;- delete clone.isOwned;+ // this check requires that updatePojo is not static+ if (entity.updatePojo) {+ await entity.updatePojo(clone);+ }++ // indicates whether entity actually changeddelete clone.isChanged;- delete clone.origParentNoteId;- delete clone.isContentAvailable;- delete clone.__attributeCache;for (const key in clone) {// !isBuffer is for images and attachments