mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
converted file, script, search and sender routes
This commit is contained in:
@@ -1,55 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const auth = require('../../services/auth');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const labels = require('../../services/labels');
|
||||
const script = require('../../services/script');
|
||||
const Repository = require('../../services/repository');
|
||||
|
||||
router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function exec(req) {
|
||||
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
|
||||
|
||||
res.send({
|
||||
return {
|
||||
executionResult: ret
|
||||
});
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
router.post('/run/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function run(req) {
|
||||
const repository = new Repository(req);
|
||||
const note = await repository.getNote(req.params.noteId);
|
||||
|
||||
const ret = await script.executeNote(req, note);
|
||||
|
||||
res.send({
|
||||
return {
|
||||
executionResult: ret
|
||||
});
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function getStartupBundles(req) {
|
||||
const repository = new Repository(req);
|
||||
const notes = await labels.getNotesWithLabel(repository, "run", "frontend_startup");
|
||||
|
||||
const scripts = [];
|
||||
const bundles = [];
|
||||
|
||||
for (const note of notes) {
|
||||
const bundle = await script.getScriptBundle(note);
|
||||
|
||||
if (bundle) {
|
||||
scripts.push(bundle);
|
||||
bundles.push(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
res.send(scripts);
|
||||
}));
|
||||
return bundles;
|
||||
}
|
||||
|
||||
router.get('/bundle/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function getBundle(req) {
|
||||
const repository = new Repository(req);
|
||||
const note = await repository.getNote(req.params.noteId);
|
||||
const bundle = await script.getScriptBundle(note);
|
||||
|
||||
res.send(bundle);
|
||||
}));
|
||||
return bundle;
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
module.exports = {
|
||||
exec,
|
||||
run,
|
||||
getStartupBundles,
|
||||
getBundle
|
||||
};
|
||||
Reference in New Issue
Block a user