feat: add cat api
This commit is contained in:
parent
95128891e1
commit
024cb507d1
19
src/index.ts
19
src/index.ts
|
@ -12,6 +12,7 @@ import {
|
||||||
} from "@lumeweb/kernel-swarm-client";
|
} from "@lumeweb/kernel-swarm-client";
|
||||||
import Protomux from "@lumeweb/kernel-protomux-client";
|
import Protomux from "@lumeweb/kernel-protomux-client";
|
||||||
import {
|
import {
|
||||||
|
CID,
|
||||||
CID_HASH_TYPES,
|
CID_HASH_TYPES,
|
||||||
createKeyPair,
|
createKeyPair,
|
||||||
createNode,
|
createNode,
|
||||||
|
@ -37,6 +38,7 @@ addHandler("setRegistryEntry", handleSetRegistryEntry);
|
||||||
addHandler("registrySubscription", handleRegistrySubscription, {
|
addHandler("registrySubscription", handleRegistrySubscription, {
|
||||||
receiveUpdates: true,
|
receiveUpdates: true,
|
||||||
});
|
});
|
||||||
|
addHandler("cat", handleCat);
|
||||||
|
|
||||||
async function handlePresentKey(aq: ActiveQuery) {
|
async function handlePresentKey(aq: ActiveQuery) {
|
||||||
handlePresentKeyModule({
|
handlePresentKeyModule({
|
||||||
|
@ -178,3 +180,20 @@ async function handleRegistrySubscription(aq: ActiveQuery) {
|
||||||
await wait.promise;
|
await wait.promise;
|
||||||
aq.respond();
|
aq.respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleCat(aq: ActiveQuery) {
|
||||||
|
if (!("cid" in aq.callerInput)) {
|
||||||
|
aq.reject("cid required");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ret = await node.downloadBytesByHash(
|
||||||
|
CID.decode(aq.callerInput.cid as string).hash,
|
||||||
|
);
|
||||||
|
|
||||||
|
aq.respond(ret);
|
||||||
|
} catch (e) {
|
||||||
|
aq.reject(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue