mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
API changes necessary to port reddit plugin, closes #58
This commit is contained in:
parent
a555b6319c
commit
f0bea9cf71
@ -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).
|
||||
|
@ -13,9 +13,9 @@ const api = (function() {
|
||||
$pluginButtons.append(button);
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
addButtonToToolbar,
|
||||
activateNote
|
||||
activateNote,
|
||||
getInstanceName: noteTree.getInstanceName
|
||||
}
|
||||
})();
|
@ -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
|
||||
};
|
||||
})();
|
@ -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')
|
||||
|
@ -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;
|
||||
|
@ -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}`);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user