2018-01-24 10:59:30 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-25 10:02:26 +08:00
|
|
|
const labels = require('../../services/labels');
|
2018-01-27 12:40:48 +08:00
|
|
|
const script = require('../../services/script');
|
2018-03-31 21:07:58 +08:00
|
|
|
const repository = require('../../services/repository');
|
2018-01-24 10:59:30 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
async function exec(req) {
|
2018-03-07 12:04:35 +08:00
|
|
|
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
|
2018-01-24 10:59:30 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
return {
|
2018-03-06 12:19:46 +08:00
|
|
|
executionResult: ret
|
2018-03-31 05:29:13 +08:00
|
|
|
};
|
|
|
|
}
|
2018-03-06 12:19:46 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
async function run(req) {
|
2018-03-06 12:19:46 +08:00
|
|
|
const note = await repository.getNote(req.params.noteId);
|
|
|
|
|
2018-03-07 12:04:35 +08:00
|
|
|
const ret = await script.executeNote(req, note);
|
2018-03-06 12:19:46 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
return {
|
2018-01-31 11:44:46 +08:00
|
|
|
executionResult: ret
|
2018-03-31 05:29:13 +08:00
|
|
|
};
|
|
|
|
}
|
2018-01-24 10:59:30 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
async function getStartupBundles(req) {
|
2018-03-31 21:07:58 +08:00
|
|
|
const notes = await labels.getNotesWithLabel("run", "frontend_startup");
|
2018-01-26 12:49:03 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
const bundles = [];
|
2018-01-26 12:49:03 +08:00
|
|
|
|
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-09 12:36:08 +08:00
|
|
|
if (bundle) {
|
2018-03-31 05:29:13 +08:00
|
|
|
bundles.push(bundle);
|
2018-03-09 12:36:08 +08:00
|
|
|
}
|
2018-01-26 12:49:03 +08:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
return bundles;
|
|
|
|
}
|
2018-01-26 12:49:03 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
async function getBundle(req) {
|
2018-03-03 22:11:41 +08:00
|
|
|
const note = await repository.getNote(req.params.noteId);
|
2018-03-31 21:07:58 +08:00
|
|
|
return await script.getScriptBundle(note);
|
2018-03-31 05:29:13 +08:00
|
|
|
}
|
2018-01-24 11:53:27 +08:00
|
|
|
|
2018-03-31 05:29:13 +08:00
|
|
|
module.exports = {
|
|
|
|
exec,
|
|
|
|
run,
|
|
|
|
getStartupBundles,
|
|
|
|
getBundle
|
|
|
|
};
|