2018-01-24 10:59:30 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const auth = require('../../services/auth');
|
|
|
|
const wrap = require('express-promise-wrap').wrap;
|
2018-01-26 12:49:03 +08:00
|
|
|
const attributes = require('../../services/attributes');
|
2018-01-27 12:40:48 +08:00
|
|
|
const script = require('../../services/script');
|
2018-01-30 12:17:44 +08:00
|
|
|
const Repository = require('../../services/repository');
|
2018-01-24 10:59:30 +08:00
|
|
|
|
2018-01-31 11:44:46 +08:00
|
|
|
router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
|
2018-03-05 12:28:26 +08:00
|
|
|
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId);
|
2018-01-24 10:59:30 +08:00
|
|
|
|
2018-01-31 11:44:46 +08:00
|
|
|
res.send({
|
|
|
|
executionResult: ret
|
|
|
|
});
|
2018-01-24 10:59:30 +08:00
|
|
|
}));
|
|
|
|
|
2018-01-26 12:49:03 +08:00
|
|
|
router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
|
2018-02-03 23:37:57 +08:00
|
|
|
const repository = new Repository(req);
|
2018-03-05 03:21:11 +08:00
|
|
|
const notes = await attributes.getNotesWithAttribute(repository, "run", "frontend_startup");
|
2018-01-26 12:49:03 +08:00
|
|
|
|
|
|
|
const scripts = [];
|
|
|
|
|
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
|
|
|
|
2018-03-05 12:28:26 +08:00
|
|
|
scripts.push(bundle);
|
2018-01-26 12:49:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
res.send(scripts);
|
|
|
|
}));
|
|
|
|
|
2018-01-24 11:53:27 +08:00
|
|
|
router.get('/subtree/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
2018-01-30 12:17:44 +08:00
|
|
|
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);
|
2018-01-26 12:22:19 +08:00
|
|
|
|
2018-03-05 12:28:26 +08:00
|
|
|
res.send(bundle);
|
2018-01-24 11:53:27 +08:00
|
|
|
}));
|
|
|
|
|
2018-03-04 23:32:53 +08:00
|
|
|
router.get('/render/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|
|
|
const repository = new Repository(req);
|
|
|
|
const note = await repository.getNote(req.params.noteId);
|
2018-03-05 12:28:26 +08:00
|
|
|
const bundle = await script.getRenderScript(note);
|
2018-03-04 23:32:53 +08:00
|
|
|
|
2018-03-05 12:28:26 +08:00
|
|
|
res.send(bundle);
|
2018-03-04 23:32:53 +08:00
|
|
|
}));
|
|
|
|
|
2018-01-24 10:59:30 +08:00
|
|
|
module.exports = router;
|