fix protecting attachments

This commit is contained in:
zadam
2023-09-08 00:19:30 +02:00
parent 3a83d58b25
commit 83f19c0537
3 changed files with 32 additions and 14 deletions

View File

@@ -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;
// this will force de/encryption
revision.setContent(content, {forceSave: true});
} catch (e) {
log.error(`Could not un/protect note revision '${revision.revisionId}'`);
throw e;
}
}
try {
const content = revision.getContent();
for (const attachment of revision.getAttachments()) {
if (note.isProtected !== attachment.isProtected) {
try {
const content = attachment.getContent();
revision.isProtected = note.isProtected;
attachment.isProtected = note.isProtected;
attachment.setContent(content, {forceSave: true});
} catch (e) {
log.error(`Could not un/protect attachment '${attachment.attachmentId}'`);
// this will force de/encryption
revision.setContent(content, {forceSave: true});
} catch (e) {
log.error(`Could not un/protect note revision '${revision.revisionId}'`);
throw e;
throw e;
}
}
}
}
}