*Add getMethods to RPCServer for plugin api

This commit is contained in:
Derrick Hammer 2022-08-26 22:38:32 -04:00
parent ad9d838d20
commit 0c577c43bd
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 15 additions and 0 deletions

View File

@ -54,6 +54,7 @@ export class PluginApiManager {
getRpcServer().registerMethod(pluginName, methodName, method); getRpcServer().registerMethod(pluginName, methodName, method);
}, },
loadPlugin: getPluginAPI().loadPlugin, loadPlugin: getPluginAPI().loadPlugin,
getMethods: getRpcServer().getMethods,
}; };
} }
} }

View File

@ -64,6 +64,18 @@ export class RPCServer {
methodMap.set(methodName, options); methodMap.set(methodName, options);
} }
public getMethods(): string[] {
const methods = [];
for (const module in this.methods) {
for (const method in this.methods.get(module)) {
methods.push(`${module}.${method}`);
}
}
return methods;
}
private async init(): Promise<void> { private async init(): Promise<void> {
(await getDHT("server")).on( (await getDHT("server")).on(
"connection", "connection",

View File

@ -1,5 +1,6 @@
import { JSONSchemaType } from "ajv"; import { JSONSchemaType } from "ajv";
import { PluginApiManager } from "./plugin.js"; import { PluginApiManager } from "./plugin.js";
import { RPCServer } from "./rpc/server.js";
export interface RPCRequest { export interface RPCRequest {
bypassCache?: boolean; bypassCache?: boolean;
@ -59,6 +60,7 @@ export interface PluginAPI {
config: any; config: any;
registerMethod: (methodName: string, method: RPCMethod) => void; registerMethod: (methodName: string, method: RPCMethod) => void;
loadPlugin: PluginApiManager["loadPlugin"]; loadPlugin: PluginApiManager["loadPlugin"];
getMethods: RPCServer["getMethods"];
} }
export type PluginFunction = (api: PluginAPI) => Promise<void>; export type PluginFunction = (api: PluginAPI) => Promise<void>;