*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", { api.registerMethod("clear_cached_item", {
cacheable: false, cacheable: false,
async handler(req: RPCClearCacheRequest): Promise<RPCClearCacheResponse> { async handler(req: string): Promise<RPCClearCacheResponse> {
if (req?.relays?.length) { if (typeof req !== "string") {
let resp = await broadcastRequest( throw new Error("item must be a string");
{
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;
} }
try { try {
api.getRpcServer().cache.deleteItem(req.request); api.getRpcServer().cache.deleteItem(req);
} catch (e: any) { } catch (e: any) {
throw e; throw e;
} }