Files
Trilium/src/services/attachments.js

38 lines
974 B
JavaScript
Raw Normal View History

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) {
if (!protectedSession.isProtectedSessionAvailable()) {
2023-03-16 11:03:28 +01:00
log.error("Protected session is not available to fix note attachments.");
return;
}
try {
2023-03-16 12:17:55 +01:00
const content = attachment.getContent();
2023-03-16 12:17:55 +01:00
attachment.isProtected = note.isProtected;
// this will force de/encryption
2023-03-16 12:17:55 +01:00
attachment.setContent(content);
2023-03-16 12:17:55 +01:00
attachment.save();
}
catch (e) {
2023-03-16 12:17:55 +01:00
log.error(`Could not un/protect note attachment ID = ${attachment.attachmentId}`);
throw e;
}
}
}
}
module.exports = {
2023-03-16 12:17:55 +01:00
protectAttachments
}