trilium/src/routes/api/script.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

"use strict";
const labels = require('../../services/labels');
const script = require('../../services/script');
const Repository = require('../../services/repository');
async function exec(req) {
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
return {
executionResult: ret
};
}
async function run(req) {
const repository = new Repository(req);
const note = await repository.getNote(req.params.noteId);
const ret = await script.executeNote(req, note);
return {
executionResult: ret
};
}
async function getStartupBundles(req) {
2018-02-03 23:37:57 +08:00
const repository = new Repository(req);
const notes = await labels.getNotesWithLabel(repository, "run", "frontend_startup");
const bundles = [];
2018-03-05 03:21:11 +08:00
for (const note of notes) {
const bundle = await script.getScriptBundle(note);
2018-03-03 22:11:41 +08:00
if (bundle) {
bundles.push(bundle);
}
}
return bundles;
}
async function getBundle(req) {
const repository = new Repository(req);
2018-03-03 22:11:41 +08:00
const note = await repository.getNote(req.params.noteId);
2018-03-05 03:21:11 +08:00
const bundle = await script.getScriptBundle(note);
return bundle;
}
module.exports = {
exec,
run,
getStartupBundles,
getBundle
};