add backend API methods to access options, attachments, revisions, etapi tokens

This commit is contained in:
zadam
2023-10-31 22:26:56 +01:00
parent de8c351e25
commit 7d80fe19e0
6 changed files with 1430 additions and 130 deletions

View File

@@ -48,6 +48,7 @@ const specialNotesService = require("./special_notes");
const branchService = require("./branches");
const exportService = require("./export/zip");
const syncMutex = require("./sync_mutex.js");
const optionsService = require("./options");
/**
@@ -90,18 +91,18 @@ function BackendScriptApi(currentNote, apiParams) {
/**
* Axios library for HTTP requests. See {@link https://axios-http.com} for documentation
* @type {axios}
* @type {axios}
* @deprecated use native (browser compatible) fetch() instead
*/
this.axios = axios;
/**
* day.js library for date manipulation. See {@link https://day.js.org} for documentation
* day.js library for date manipulation. See {@link https://day.js.org} for documentation
* @type {dayjs}
*/
this.dayjs = dayjs;
/**
/**
* xml2js library for XML parsing. See {@link https://github.com/Leonidas-from-XIV/node-xml2js} for documentation
* @type {xml2js}
* @type {xml2js}
*/
this.xml2js = xml2js;
@@ -134,6 +135,53 @@ function BackendScriptApi(currentNote, apiParams) {
*/
this.getAttribute = attributeId => becca.getAttribute(attributeId);
/**
* @method
* @param {string} attachmentId
* @returns {BAttachment|null}
*/
this.getAttachment = attachmentId => becca.getAttachment(attachmentId);
/**
* @method
* @param {string} revisionId
* @returns {BRevision|null}
*/
this.getRevision = revisionId => becca.getRevision(revisionId);
/**
* @method
* @param {string} etapiTokenId
* @returns {BEtapiToken|null}
*/
this.getEtapiToken = etapiTokenId => becca.getEtapiToken(etapiTokenId);
/**
* @method
* @returns {BEtapiToken[]}
*/
this.getEtapiTokens = () => becca.getEtapiTokens();
/**
* @method
* @param {string} optionName
* @returns {BOption|null}
*/
this.getOption = optionName => becca.getOption(optionName);
/**
* @method
* @returns {BOption[]}
*/
this.getOptions = () => optionsService.getOptions();
/**
* @method
* @param {string} attributeId
* @returns {BAttribute|null}
*/
this.getAttribute = attributeId => becca.getAttribute(attributeId);
/**
* This is a powerful search method - you can search by attributes and their values, e.g.:
* "#dateModified =* MONTH AND #log". See {@link https://github.com/zadam/trilium/wiki/Search} for full documentation for all options
@@ -402,7 +450,7 @@ function BackendScriptApi(currentNote, apiParams) {
this.getWeekNote = dateNoteService.getWeekNote;
/**
* Returns month note for given date. If such note doesn't exist, it is created.
* Returns month note for given date. If such a note doesn't exist, it is created.
*
* @method
* @param {string} date in YYYY-MM format
@@ -412,7 +460,7 @@ function BackendScriptApi(currentNote, apiParams) {
this.getMonthNote = dateNoteService.getMonthNote;
/**
* Returns year note for given year. If such note doesn't exist, it is created.
* Returns year note for given year. If such a note doesn't exist, it is created.
*
* @method
* @param {string} year in YYYY format
@@ -498,7 +546,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @returns {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version
*/
this.getAppInfo = () => appInfo
this.getAppInfo = () => appInfo;
/**
* Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.
@@ -589,7 +637,7 @@ function BackendScriptApi(currentNote, apiParams) {
/**
* Executes given anonymous function on the frontend(s).
* Internally this serializes the anonymous function into string and sends it to frontend(s) via WebSocket.
* Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket.
* Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all
* instances execute the given function.
*