2019-11-09 11:58:52 +01:00
|
|
|
"use strict";
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import log from "./log.js";
|
|
|
|
import sql from "./sql.js";
|
|
|
|
import protectedSessionService from "./protected_session.js";
|
|
|
|
import dateUtils from "./date_utils.js";
|
|
|
|
import BNote from "../becca/entities/bnote.js";
|
2024-02-17 19:44:46 +02:00
|
|
|
|
|
|
|
function protectRevisions(note: BNote) {
|
2023-04-14 16:49:06 +02:00
|
|
|
if (!protectedSessionService.isProtectedSessionAvailable()) {
|
|
|
|
throw new Error(`Cannot (un)protect revisions of note '${note.noteId}' without active protected session`);
|
|
|
|
}
|
2022-06-13 22:54:08 +02:00
|
|
|
|
2023-06-04 23:01:40 +02:00
|
|
|
for (const revision of note.getRevisions()) {
|
2023-09-08 00:19:30 +02:00
|
|
|
if (note.isProtected !== revision.isProtected) {
|
|
|
|
try {
|
|
|
|
const content = revision.getContent();
|
|
|
|
|
2024-02-17 19:44:46 +02:00
|
|
|
revision.isProtected = !!note.isProtected;
|
2019-11-09 13:01:05 +01:00
|
|
|
|
2023-09-08 00:19:30 +02:00
|
|
|
// this will force de/encryption
|
|
|
|
revision.setContent(content, {forceSave: true});
|
|
|
|
} catch (e) {
|
|
|
|
log.error(`Could not un/protect note revision '${revision.revisionId}'`);
|
|
|
|
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2019-11-09 11:58:52 +01:00
|
|
|
|
2023-09-08 00:19:30 +02:00
|
|
|
for (const attachment of revision.getAttachments()) {
|
|
|
|
if (note.isProtected !== attachment.isProtected) {
|
|
|
|
try {
|
|
|
|
const content = attachment.getContent();
|
2019-11-09 13:01:05 +01:00
|
|
|
|
2023-09-08 00:19:30 +02:00
|
|
|
attachment.isProtected = note.isProtected;
|
|
|
|
attachment.setContent(content, {forceSave: true});
|
|
|
|
} catch (e) {
|
|
|
|
log.error(`Could not un/protect attachment '${attachment.attachmentId}'`);
|
2020-12-09 22:49:55 +01:00
|
|
|
|
2023-09-08 00:19:30 +02:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2019-11-09 11:58:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2023-12-04 00:11:24 +01:00
|
|
|
protectRevisions
|
2020-06-20 12:31:38 +02:00
|
|
|
};
|