*Simplify clear_cached_item so it just needs to use broadcast_request as a proxy

This commit is contained in:
Derrick Hammer 2022-11-27 18:10:21 -05:00
parent 86ce21a4b4
commit 364e628c7a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 4 additions and 30 deletions

View File

@ -56,38 +56,12 @@ const plugin: Plugin = {
});
api.registerMethod("clear_cached_item", {
cacheable: false,
async handler(req: RPCClearCacheRequest): Promise<RPCClearCacheResponse> {
if (req?.relays?.length) {
let resp = await broadcastRequest(
{
module: "rpc",
method: "clear_cached_item",
data: req.request,
},
req?.relays
);
let results: RPCClearCacheResponse = {
relays: {},
data: true,
signedField: "relays",
};
for (const relay in resp) {
let ret: RPCClearCacheResponse;
try {
ret = await resp.get(relay);
} catch (e: any) {
(results.relays as RPCClearCacheResponseRelayList)[relay] = {
error: e.message,
};
}
}
return results;
async handler(req: string): Promise<RPCClearCacheResponse> {
if (typeof req !== "string") {
throw new Error("item must be a string");
}
try {
api.getRpcServer().cache.deleteItem(req.request);
api.getRpcServer().cache.deleteItem(req);
} catch (e: any) {
throw e;
}