add "api.runOnFrontend()" to the backend script API

This commit is contained in:
zadam
2023-08-30 23:18:16 +02:00
parent 8da5b90aea
commit 6f7fbacca1
9 changed files with 302 additions and 20 deletions
+5 -2
View File
@@ -4,8 +4,11 @@ import toastService from "./toast.js";
import froca from "./froca.js";
import utils from "./utils.js";
async function getAndExecuteBundle(noteId, originEntity = null) {
const bundle = await server.get(`script/bundle/${noteId}`);
async function getAndExecuteBundle(noteId, originEntity = null, script = null, params = null) {
const bundle = await server.post(`script/bundle/${noteId}`, {
script,
params
});
return await executeBundle(bundle, originEntity);
}
+1 -1
View File
@@ -10,7 +10,7 @@ async function render(note, $el) {
$el.empty().toggle(renderNoteIds.length > 0);
for (const renderNoteId of renderNoteIds) {
const bundle = await server.get(`script/bundle/${renderNoteId}`);
const bundle = await server.post(`script/bundle/${renderNoteId}`);
const $scriptContainer = $('<div>');
$el.append($scriptContainer);
+7
View File
@@ -125,6 +125,13 @@ async function handleMessage(event) {
else if (message.type === 'toast') {
toastService.showMessage(message.message);
}
else if (message.type === 'execute-script') {
const bundleService = (await import("../services/bundle.js")).default;
const froca = (await import("../services/froca.js")).default;
const originEntity = message.originEntityId ? await froca.getNote(message.originEntityId) : null;
bundleService.getAndExecuteBundle(message.currentNoteId, originEntity, message.script, message.params);
}
}
let entityChangeIdReachedListeners = [];