mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-04-23 21:29:02 -05:00
add "api.runOnFrontend()" to the backend script API
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user