2023-03-08 09:01:23 +01:00
|
|
|
const protectedSession = require("./protected_session");
|
|
|
|
|
const log = require("./log");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {BNote} note
|
|
|
|
|
*/
|
2023-03-16 12:17:55 +01:00
|
|
|
function protectAttachments(note) {
|
|
|
|
|
for (const attachment of note.getAttachments()) {
|
|
|
|
|
if (note.isProtected !== attachment.isProtected) {
|
2023-03-08 09:01:23 +01:00
|
|
|
if (!protectedSession.isProtectedSessionAvailable()) {
|
2023-03-16 11:03:28 +01:00
|
|
|
log.error("Protected session is not available to fix note attachments.");
|
2023-03-08 09:01:23 +01:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2023-03-16 12:17:55 +01:00
|
|
|
const content = attachment.getContent();
|
2023-03-08 09:01:23 +01:00
|
|
|
|
2023-03-16 12:17:55 +01:00
|
|
|
attachment.isProtected = note.isProtected;
|
2023-03-08 09:01:23 +01:00
|
|
|
|
|
|
|
|
// this will force de/encryption
|
2023-03-16 12:17:55 +01:00
|
|
|
attachment.setContent(content);
|
2023-03-08 09:01:23 +01:00
|
|
|
|
2023-03-16 12:17:55 +01:00
|
|
|
attachment.save();
|
2023-03-08 09:01:23 +01:00
|
|
|
}
|
|
|
|
|
catch (e) {
|
2023-03-16 12:17:55 +01:00
|
|
|
log.error(`Could not un/protect note attachment ID = ${attachment.attachmentId}`);
|
2023-03-08 09:01:23 +01:00
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
2023-03-16 12:17:55 +01:00
|
|
|
protectAttachments
|
2023-03-08 09:01:23 +01:00
|
|
|
}
|