feat: update ApiTokenGuard to always allow access, add updateDatabase method to ProjectService, enhance QueryExecuterService with job options, integrate QueueModule in QueryModule, apply ApiTokenGuard to RedisManagerController, refactor Plugin class to include methods, implement new methods in RedisPlugin, and remove unused async.js module

This commit is contained in:
Boris D
2025-10-09 11:56:53 +03:00
parent 6c95e9d5e0
commit dac008366a
15 changed files with 169 additions and 59 deletions

View File

@ -1,6 +1,7 @@
import * as ivm from "isolated-vm";
import { VModule } from "./module.class";
import { Plugin } from "./plugin.class";
import { QueryResponse } from "./vm.constants";
export class Vm {
private memoryLimit: number;
@ -32,26 +33,49 @@ export class Vm {
}
for (const plugin of this.plugins) {
this.jail.setSync(
plugin.getName(),
new ivm.Reference(async (...args) => {
return await plugin.run(...args);
})
const pluginName = plugin.getName();
await this.context.evalClosure(
"globalThis[$0] = globalThis[$0] || Object.create(null);",
[pluginName],
{ arguments: { copy: true } }
);
for (const method of plugin.getMethods()) {
const fnRef = new ivm.Reference(async (...args) => {
return await plugin[method](...args);
});
await this.context.evalClosure(
`
const name = $0;
const method = $1;
const ref = $2;
const ns = globalThis[name];
ns[method] = (...args) => ref.apply(undefined, args, {
arguments: { copy: true },
result: { promise: true, copy: true }
});
`,
[pluginName, method, fnRef],
{ arguments: { copy: true } }
);
}
}
return this;
}
setFunction(name: string, func: (...args) => any) {
this.jail.setSync(name, func);
this.jail.setSync(name, func, { arguments: { copy: true } });
}
async runScript(
script: string,
args: Record<string, any>,
headers: Record<string, any>
): Promise<any> {
): Promise<QueryResponse> {
let resolvePromise: (value: any) => void;
let rejectPromise: (reason?: any) => void;
@ -63,7 +87,7 @@ export class Vm {
this.setFunction("returnResult", (res) => {
console.log("Returning result from VM:", res);
resolvePromise(JSON.parse(res));
resolvePromise(res);
});
// TODO: log
@ -83,7 +107,7 @@ export class Vm {
const result = await main(${JSON.stringify(
args
)}, ${JSON.stringify(headers)});
returnResult(JSON.stringify(result))
returnResult(result)
} catch (e) {
error(e)
}