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 API changes
azivner55d8ef7e81be
diff --git a/routes/api/script.js b/routes/api/script.jsindex 40cb1dabc2..95412e85a7 100644--- a/routes/api/script.js+++ b/routes/api/script.js@@ -68,8 +68,6 @@ async function getSubTreeScripts(parentId, includedNoteIds, dataKey) {script += await getSubTreeScripts(child.note_id, includedNoteIds, dataKey);- console.log('MIME: ', child.mime);-if (child.mime === 'application/javascript') {child.note_text = '<script>' + child.note_text + '</script>';}diff --git a/services/attributes.js b/services/attributes.jsindex 7ae6dd4232..7fd773a3a3 100644--- a/services/attributes.js+++ b/services/attributes.js@@ -14,17 +14,29 @@ async function getNoteIdWithAttribute(name, value) {WHERE notes.is_deleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);}-async function getNoteWithAttribute(dataKey, name, value) {- const note = await sql.getFirst(`SELECT notes.* FROM notes JOIN attributes USING(note_id)+async function getNotesWithAttribute(dataKey, name, value) {+ let notes;++ if (value !== undefined) {+ notes = await sql.getAll(`SELECT notes.* FROM notes JOIN attributes USING(note_id)WHERE notes.is_deleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);+ }+ else {+ notes = await sql.getAll(`SELECT notes.* FROM notes JOIN attributes USING(note_id)+ WHERE notes.is_deleted = 0 AND attributes.name = ?`, [name]);+ }- if (!note) {- return note;+ for (const note of notes) {+ protected_session.decryptNote(dataKey, note);}- protected_session.decryptNote(dataKey, note);+ return notes;+}++async function getNoteWithAttribute(dataKey, name, value) {+ const notes = getNotesWithAttribute(dataKey, name, value);- return note;+ return notes.length > 0 ? notes[0] : null;}async function getNoteIdsWithAttribute(name) {@@ -51,6 +63,7 @@ async function createAttribute(noteId, name, value = null, sourceId = null) {module.exports = {getNoteAttributeMap,getNoteIdWithAttribute,+ getNotesWithAttribute,getNoteWithAttribute,getNoteIdsWithAttribute,createAttributediff --git a/services/script_context.js b/services/script_context.jsindex 506ad14d66..bd16201e26 100644--- a/services/script_context.js+++ b/services/script_context.js@@ -11,7 +11,7 @@ function ScriptContext(noteId, dataKey) {this.dataKey = protected_session.getDataKey(dataKey);function deserializePayload(note) {- if (note.type === "code" && note.mime === "application/json") {+ if (note && note.type === "code" && note.mime === "application/json") {note.payload = JSON.parse(note.note_text);}}@@ -28,12 +28,20 @@ function ScriptContext(noteId, dataKey) {return note;};- this.getNoteWithAttribute = async function (attrName, attrValue) {- const note = await attributes.getNoteWithAttribute(this.dataKey, attrName, attrValue);+ this.getNotesWithAttribute = async function (attrName, attrValue) {+ const notes = await attributes.getNotesWithAttribute(this.dataKey, attrName, attrValue);- deserializePayload(note);+ for (const note of notes) {+ deserializePayload(note);+ }- return note;+ return notes;+ };++ this.getNoteWithAttribute = async function (attrName, attrValue) {+ const notes = this.getNotesWithAttribute(attrName, attrValue);++ return notes.length > 0 ? notes[0] : null;};this.createNote = async function (parentNoteId, name, payload, extraOptions = {}) {