mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
server.exec() refactored into api
This commit is contained in:
@@ -13,11 +13,37 @@ function Api() {
|
||||
$pluginButtons.append(button);
|
||||
}
|
||||
|
||||
function prepareParams(params) {
|
||||
if (!params) {
|
||||
return params;
|
||||
}
|
||||
|
||||
return params.map(p => {
|
||||
if (typeof p === "function") {
|
||||
return "!@#Function: " + p.toString();
|
||||
}
|
||||
else {
|
||||
return p;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function runOnServer(script, params) {
|
||||
if (typeof script === "function") {
|
||||
script = script.toString();
|
||||
}
|
||||
|
||||
const ret = await server.post('script/exec', { script: script, params: prepareParams(params) });
|
||||
|
||||
return ret.executionResult;
|
||||
}
|
||||
|
||||
return {
|
||||
__modules: {},
|
||||
__notes: {},
|
||||
addButtonToToolbar,
|
||||
activateNote,
|
||||
getInstanceName: noteTree.getInstanceName
|
||||
getInstanceName: noteTree.getInstanceName,
|
||||
runOnServer
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user