feat: add stat api

This commit is contained in:
Derrick Hammer 2023-11-17 09:19:33 -05:00
parent c7a578e8cd
commit 2db701fb92
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 0 deletions

View File

@ -39,6 +39,7 @@ addHandler("registrySubscription", handleRegistrySubscription, {
receiveUpdates: true, receiveUpdates: true,
}); });
addHandler("cat", handleCat); addHandler("cat", handleCat);
addHandler("stat", handleStat);
async function handlePresentKey(aq: ActiveQuery) { async function handlePresentKey(aq: ActiveQuery) {
handlePresentKeyModule({ handlePresentKeyModule({
@ -197,3 +198,16 @@ async function handleCat(aq: ActiveQuery) {
aq.reject(e); 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);
}
}