feat: add stat api
This commit is contained in:
parent
c7a578e8cd
commit
2db701fb92
14
src/index.ts
14
src/index.ts
|
@ -39,6 +39,7 @@ addHandler("registrySubscription", handleRegistrySubscription, {
|
|||
receiveUpdates: true,
|
||||
});
|
||||
addHandler("cat", handleCat);
|
||||
addHandler("stat", handleStat);
|
||||
|
||||
async function handlePresentKey(aq: ActiveQuery) {
|
||||
handlePresentKeyModule({
|
||||
|
@ -197,3 +198,16 @@ async function handleCat(aq: ActiveQuery) {
|
|||
aq.reject(e);
|
||||
}
|
||||
}
|
||||
async function handleStat(aq: ActiveQuery) {
|
||||
if (!("cid" in aq.callerInput)) {
|
||||
aq.reject("cid required");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const ret = await node.getMetadataByCID(aq.callerInput.cid);
|
||||
aq.respond(ret.toJson());
|
||||
} catch (e) {
|
||||
aq.reject(e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue