mirror of https://github.com/TriliumNext/Notes
refactored note attachment into note ancillary
parent
78954268ab
commit
37ba76fdd8
@ -0,0 +1,37 @@
|
||||
const protectedSession = require("./protected_session.js");
|
||||
const log = require("./log.js");
|
||||
|
||||
/**
|
||||
* @param {BNote} note
|
||||
*/
|
||||
function protectNoteAncillaries(note) {
|
||||
for (const noteAncillary of note.getNoteAncillaries()) {
|
||||
if (note.isProtected !== noteAncillary.isProtected) {
|
||||
if (!protectedSession.isProtectedSessionAvailable()) {
|
||||
log.error("Protected session is not available to fix note ancillaries.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = noteAncillary.getContent();
|
||||
|
||||
noteAncillary.isProtected = note.isProtected;
|
||||
|
||||
// this will force de/encryption
|
||||
noteAncillary.setContent(content);
|
||||
|
||||
noteAncillary.save();
|
||||
}
|
||||
catch (e) {
|
||||
log.error(`Could not un/protect note ancillary ID = ${noteAncillary.noteAncillaryId}`);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
protectNoteAncillaries
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
const protectedSession = require("./protected_session.js");
|
||||
const log = require("./log.js");
|
||||
|
||||
/**
|
||||
* @param {BNote} note
|
||||
*/
|
||||
function protectNoteAttachments(note) {
|
||||
for (const noteAttachment of note.getNoteAttachments()) {
|
||||
if (note.isProtected !== noteAttachment.isProtected) {
|
||||
if (!protectedSession.isProtectedSessionAvailable()) {
|
||||
log.error("Protected session is not available to fix note attachments.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const content = noteAttachment.getContent();
|
||||
|
||||
noteAttachment.isProtected = note.isProtected;
|
||||
|
||||
// this will force de/encryption
|
||||
noteAttachment.setContent(content);
|
||||
|
||||
noteAttachment.save();
|
||||
}
|
||||
catch (e) {
|
||||
log.error(`Could not un/protect note attachment ID = ${noteAttachment.noteAttachmentId}`);
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
protectNoteAttachments
|
||||
}
|
||||
Loading…
Reference in New Issue