mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
"use strict";
|
|
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
const auth = require('../../services/auth');
|
|
const wrap = require('express-promise-wrap').wrap;
|
|
const attributes = require('../../services/attributes');
|
|
const script = require('../../services/script');
|
|
const Repository = require('../../services/repository');
|
|
|
|
router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId);
|
|
|
|
res.send({
|
|
executionResult: ret
|
|
});
|
|
}));
|
|
|
|
router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|
const repository = new Repository(req);
|
|
const notes = await attributes.getNotesWithAttribute(repository, "run", "frontend_startup");
|
|
|
|
const scripts = [];
|
|
|
|
for (const note of notes) {
|
|
const bundle = await script.getScriptBundle(note);
|
|
|
|
scripts.push(bundle);
|
|
}
|
|
|
|
res.send(scripts);
|
|
}));
|
|
|
|
router.get('/subtree/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|
const repository = new Repository(req);
|
|
const note = await repository.getNote(req.params.noteId);
|
|
const bundle = await script.getScriptBundle(note);
|
|
|
|
res.send(bundle);
|
|
}));
|
|
|
|
router.get('/render/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|
const repository = new Repository(req);
|
|
const note = await repository.getNote(req.params.noteId);
|
|
const bundle = await script.getRenderScript(note);
|
|
|
|
res.send(bundle);
|
|
}));
|
|
|
|
module.exports = router; |