mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import ScriptContext from "./script_context.js";
|
|
import server from "./server.js";
|
|
|
|
async function getAndExecuteBundle(noteId, workEntity = null) {
|
|
const bundle = await server.get('script/bundle/' + noteId);
|
|
|
|
await executeBundle(bundle, workEntity);
|
|
}
|
|
|
|
async function executeBundle(bundle, workEntity) {
|
|
const apiContext = ScriptContext(bundle.note, bundle.allNotes, workEntity);
|
|
|
|
return await (function () {
|
|
return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`);
|
|
}.call(apiContext));
|
|
}
|
|
|
|
async function executeStartupBundles() {
|
|
const scriptBundles = await server.get("script/startup");
|
|
|
|
for (const bundle of scriptBundles) {
|
|
await executeBundle(bundle);
|
|
}
|
|
}
|
|
|
|
async function executeRelationBundles(note, relationName) {
|
|
const bundlesToRun = await server.get("script/relation/" + note.noteId + "/" + relationName);
|
|
|
|
for (const bundle of bundlesToRun) {
|
|
await executeBundle(bundle, note);
|
|
}
|
|
}
|
|
|
|
export default {
|
|
executeBundle,
|
|
getAndExecuteBundle,
|
|
executeStartupBundles,
|
|
executeRelationBundles
|
|
} |