mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server.exec() refactored into api
This commit is contained in:
parent
07bf075894
commit
5c91e38dfe
@ -13,11 +13,37 @@ function Api() {
|
|||||||
$pluginButtons.append(button);
|
$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 {
|
return {
|
||||||
__modules: {},
|
__modules: {},
|
||||||
__notes: {},
|
__notes: {},
|
||||||
addButtonToToolbar,
|
addButtonToToolbar,
|
||||||
activateNote,
|
activateNote,
|
||||||
getInstanceName: noteTree.getInstanceName
|
getInstanceName: noteTree.getInstanceName,
|
||||||
|
runOnServer
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,31 +31,6 @@ const server = (function() {
|
|||||||
return await call('DELETE', url);
|
return await call('DELETE', url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareParams(params) {
|
|
||||||
if (!params) {
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
return params.map(p => {
|
|
||||||
if (typeof p === "function") {
|
|
||||||
return "!@#Function: " + p.toString();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function exec(params, script) {
|
|
||||||
if (typeof script === "function") {
|
|
||||||
script = script.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
const ret = await post('script/exec', { script: script, params: prepareParams(params) });
|
|
||||||
|
|
||||||
return ret.executionResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
let i = 1;
|
let i = 1;
|
||||||
const reqResolves = {};
|
const reqResolves = {};
|
||||||
|
|
||||||
@ -119,7 +94,6 @@ const server = (function() {
|
|||||||
post,
|
post,
|
||||||
put,
|
put,
|
||||||
remove,
|
remove,
|
||||||
exec,
|
|
||||||
ajax,
|
ajax,
|
||||||
// don't remove, used from CKEditor image upload!
|
// don't remove, used from CKEditor image upload!
|
||||||
getHeaders
|
getHeaders
|
||||||
|
@ -123,8 +123,6 @@ function executeScript(script) {
|
|||||||
${script}
|
${script}
|
||||||
})();`;
|
})();`;
|
||||||
|
|
||||||
console.log(completeScript);
|
|
||||||
|
|
||||||
eval(completeScript);
|
eval(completeScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user