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
script related changes
azivner9a091408e345
diff --git a/src/entities/note.js b/src/entities/note.jsindex 9e255df1a8..35a0b0e3b8 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -3,6 +3,14 @@const Entity = require('./entity');class Note extends Entity {+ constructor(sql, row) {+ super(sql, row);++ if (this.type === "code" && this.mime === "application/json") {+ this.jsonContent = JSON.parse(this.content);+ }+ }+async getAttributes() {return this.sql.getEntities("SELECT * FROM attributes WHERE noteId = ?", [this.noteId]);}diff --git a/src/services/attributes.js b/src/services/attributes.jsindex 650d2c7ce3..08419ef618 100644--- a/src/services/attributes.js+++ b/src/services/attributes.js@@ -18,11 +18,11 @@ async function getNotesWithAttribute(dataKey, name, value) {let notes;if (value !== undefined) {- notes = await sql.getRows(`SELECT notes.* FROM notes JOIN attributes USING(noteId)+ notes = await sql.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)WHERE notes.isDeleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);}else {- notes = await sql.getRows(`SELECT notes.* FROM notes JOIN attributes USING(noteId)+ notes = await sql.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)WHERE notes.isDeleted = 0 AND attributes.name = ?`, [name]);}diff --git a/src/services/notes.js b/src/services/notes.jsindex 71dd34dcbf..010c533d07 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -6,7 +6,7 @@ const attributes = require('./attributes');const protected_session = require('./protected_session');async function getNoteById(noteId, dataKey) {- const note = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId]);+ const note = await sql.getEntity("SELECT * FROM notes WHERE noteId = ?", [noteId]);protected_session.decryptNote(dataKey, note);diff --git a/src/services/script_context.js b/src/services/script_context.jsindex 76b2ec78aa..a6bddba484 100644--- a/src/services/script_context.js+++ b/src/services/script_context.js@@ -10,32 +10,16 @@ function ScriptContext(noteId, dataKey) {this.scriptNoteId = noteId;this.dataKey = protected_session.getDataKey(dataKey);- function deserializePayload(note) {- if (note && note.type === "code" && note.mime === "application/json") {- note.payload = JSON.parse(note.content);- }- }-function serializePayload(payload) {return JSON.stringify(payload, null, '\t');}this.getNoteById = async function(noteId) {- const note = await notes.getNoteById(noteId, this.dataKey);-- deserializePayload(note);-- return note;+ return notes.getNoteById(noteId, this.dataKey);};this.getNotesWithAttribute = async function (attrName, attrValue) {- const notes = await attributes.getNotesWithAttribute(this.dataKey, attrName, attrValue);-- for (const note of notes) {- deserializePayload(note);- }-- return notes;+ return await attributes.getNotesWithAttribute(this.dataKey, attrName, attrValue);};this.getNoteWithAttribute = async function (attrName, attrValue) {@@ -77,12 +61,10 @@ function ScriptContext(noteId, dataKey) {this.updateNote = async function (note) {if (note.type === 'code' && note.mime === 'application/json') {- note.content = serializePayload(note.payload);+ note.content = serializePayload(note.jsonContent);}- log.info("new note text: ", note.content);-- delete note.payload;+ delete note.jsonContent;if (note.isProtected) {protected_session.encryptNote(this.dataKey, note);