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