Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(core): integrate revisions
Elian Doranedac58f3fab6
diff --git a/apps/server/src/services/revisions.ts b/apps/server/src/services/revisions.tsindex 1265d49272..ae8f826b0c 100644--- a/apps/server/src/services/revisions.ts+++ b/apps/server/src/services/revisions.ts@@ -1,49 +1,2 @@-"use strict";--import log from "./log.js";-import sql from "./sql.js";-import protectedSessionService from "./protected_session.js";-import dateUtils from "./date_utils.js";-import type BNote from "../becca/entities/bnote.js";--function protectRevisions(note: BNote) {- if (!protectedSessionService.isProtectedSessionAvailable()) {- throw new Error(`Cannot (un)protect revisions of note '${note.noteId}' without active protected session`);- }-- for (const revision of note.getRevisions()) {- 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;- }- }-- for (const attachment of revision.getAttachments()) {- if (note.isProtected !== attachment.isProtected) {- try {- const content = attachment.getContent();-- attachment.isProtected = note.isProtected;- attachment.setContent(content, { forceSave: true });- } catch (e) {- log.error(`Could not un/protect attachment '${attachment.attachmentId}'`);-- throw e;- }- }- }- }-}--export default {- protectRevisions-};+import { revisions } from "@triliumnext/core";+export default revisions;diff --git a/packages/trilium-core/src/index.ts b/packages/trilium-core/src/index.tsindex 21aff83f3f..482ba098f8 100644--- a/packages/trilium-core/src/index.ts+++ b/packages/trilium-core/src/index.ts@@ -30,6 +30,7 @@ export { default as tree } from "./services/tree";export { default as cloning } from "./services/cloning";export { default as handlers } from "./services/handlers";export { default as TaskContext } from "./services/task_context";+export { default as revisions } from "./services/revisions";export { default as becca } from "./becca/becca";export { default as becca_loader } from "./becca/becca_loader";diff --git a/packages/trilium-core/src/services/revisions.ts b/packages/trilium-core/src/services/revisions.tsnew file mode 100644index 0000000000..b450e05d5b--- /dev/null+++ b/packages/trilium-core/src/services/revisions.ts@@ -0,0 +1,46 @@+import { getLog } from "./log.js";+import protectedSessionService from "./protected_session.js";+import type BNote from "../becca/entities/bnote.js";++function protectRevisions(note: BNote) {+ if (!protectedSessionService.isProtectedSessionAvailable()) {+ throw new Error(`Cannot (un)protect revisions of note '${note.noteId}' without active protected session`);+ }++ const log = getLog();+ for (const revision of note.getRevisions()) {+ 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;+ }+ }++ for (const attachment of revision.getAttachments()) {+ if (note.isProtected !== attachment.isProtected) {+ try {+ const content = attachment.getContent();++ attachment.isProtected = note.isProtected;+ attachment.setContent(content, { forceSave: true });+ } catch (e) {+ log.error(`Could not un/protect attachment '${attachment.attachmentId}'`);++ throw e;+ }+ }+ }+ }+}++export default {+ protectRevisions+};