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
API changes necessary to port reddit plugin, closes #58
azivnerf0bea9cf71c9
diff --git a/config-sample.ini b/config-sample.iniindex b5b8e798dc..634a704dac 100644--- a/config-sample.ini+++ b/config-sample.ini@@ -1,3 +1,7 @@+[General]+# Instance name can be used to distinguish between different instances+instanceName=+[Network]port=8080# true for TLS/SSL/HTTPS (secure), false for HTTP (unsecure).diff --git a/src/public/javascripts/api.js b/src/public/javascripts/api.jsindex 20f25c36b8..c702d0de51 100644--- a/src/public/javascripts/api.js+++ b/src/public/javascripts/api.js@@ -13,9 +13,9 @@ const api = (function() {$pluginButtons.append(button);}-return {addButtonToToolbar,- activateNote+ activateNote,+ getInstanceName: noteTree.getInstanceName}})();\ No newline at end of filediff --git a/src/public/javascripts/note_tree.js b/src/public/javascripts/note_tree.jsindex b4a4c550fe..2213d5d4fc 100644--- a/src/public/javascripts/note_tree.js+++ b/src/public/javascripts/note_tree.js@@ -5,6 +5,8 @@ const noteTree = (function() {const $parentList = $("#parent-list");const $parentListList = $("#parent-list-inner");+ let instanceName = null; // should have better place+let startNotePath = null;let notesTreeMap = {};@@ -648,6 +650,7 @@ const noteTree = (function() {async function loadTree() {const resp = await server.get('tree');startNotePath = resp.start_note_path;+ instanceName = resp.instanceName;if (document.location.hash) {startNotePath = getNotePathFromAddress();@@ -823,6 +826,10 @@ const noteTree = (function() {return !!childToParents[noteId];}+ function getInstanceName() {+ return instanceName;+ }+$(document).bind('keydown', 'ctrl+o', e => {const node = getCurrentNode();const parentNoteId = node.data.parentNoteId;@@ -897,6 +904,7 @@ const noteTree = (function() {setParentChildRelation,getSelectedNodes,sortAlphabetically,- noteExists+ noteExists,+ getInstanceName};})();\ No newline at end of filediff --git a/src/routes/api/tree.js b/src/routes/api/tree.jsindex e9db493abf..f8ea3b208b 100644--- a/src/routes/api/tree.js+++ b/src/routes/api/tree.js@@ -6,6 +6,7 @@ const sql = require('../../services/sql');const options = require('../../services/options');const utils = require('../../services/utils');const auth = require('../../services/auth');+const config = require('../../services/config');const protected_session = require('../../services/protected_session');const sync_table = require('../../services/sync_table');const wrap = require('express-promise-wrap').wrap;@@ -41,6 +42,7 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {AND notes.isDeleted = 0`);res.send({+ instanceName: config.General ? config.General.instanceName : null,notes: notes,hiddenInAutocomplete: hiddenInAutocomplete,start_note_path: await options.getOption('start_note_path')diff --git a/src/services/script.js b/src/services/script.jsindex 00db4c1d01..d6244ed621 100644--- a/src/services/script.js+++ b/src/services/script.js@@ -12,7 +12,7 @@ async function executeScript(dataKey, script, params) {let ret;await sql.doInTransaction(async () => {- ret = await (function() { return eval(`(${script})(${paramsStr})`); }.call(ctx));+ ret = await (function() { return eval(`const api = this; (${script})(${paramsStr})`); }.call(ctx));});return ret;diff --git a/src/services/script_context.js b/src/services/script_context.jsindex ce508e612a..74571ee025 100644--- a/src/services/script_context.js+++ b/src/services/script_context.js@@ -3,18 +3,21 @@ const protected_session = require('./protected_session');const notes = require('./notes');const attributes = require('./attributes');const date_notes = require('./date_notes');+const config = require('./config');const Repository = require('./repository');function ScriptContext(noteId, dataKey) {- this.dataKey = protected_session.getDataKey(dataKey);- this.repository = new Repository(dataKey);+ dataKey = protected_session.getDataKey(dataKey);+ const repository = new Repository(dataKey);++ this.getInstanceName = () => config.General ? config.General.instanceName : null;this.getNoteById = async function(noteId) {- return this.repository.getNote(noteId);+ return repository.getNote(noteId);};this.getNotesWithAttribute = async function (attrName, attrValue) {- return await attributes.getNotesWithAttribute(this.dataKey, attrName, attrValue);+ return await attributes.getNotesWithAttribute(dataKey, attrName, attrValue);};this.getNoteWithAttribute = async function (attrName, attrValue) {@@ -43,7 +46,7 @@ function ScriptContext(noteId, dataKey) {note.mime = "text/html";}- const noteId = (await notes.createNewNote(parentNoteId, note, this.dataKey)).noteId;+ const noteId = (await notes.createNewNote(parentNoteId, note, dataKey)).noteId;if (extraOptions.attributes) {for (const attrName in extraOptions.attributes) {@@ -56,7 +59,7 @@ function ScriptContext(noteId, dataKey) {this.createAttribute = attributes.createAttribute;- this.updateEntity = this.repository.updateEntity;+ this.updateEntity = repository.updateEntity;this.log = message => log.info(`Script: ${message}`);