Compare commits

...

2 Commits

1 changed files with 33 additions and 14 deletions

View File

@ -238,7 +238,10 @@ async function handleStat(aq: ActiveQuery) {
aq.respond(
JSON.parse(
JSON.stringify(
await fs.stat(aq.callerInput.cid, aq.callerInput.options ?? {})
await fs.stat(
getCID(aq.callerInput.cid),
aq.callerInput.options ?? {}
)
)
)
);
@ -260,7 +263,10 @@ async function handleLs(aq: ActiveQuery) {
aborted = true;
});
const iterable = fs.ls(aq.callerInput.cid, aq.callerInput.options ?? {});
const iterable = fs.ls(
getCID(aq.callerInput.cid),
aq.callerInput.options ?? {}
);
for await (const item of iterable) {
if (aborted) {
@ -286,7 +292,10 @@ async function handleCat(aq: ActiveQuery) {
aborted = true;
});
const iterable = fs.cat(aq.callerInput.cid, aq.callerInput.options ?? {});
const iterable = fs.cat(
getCID(aq.callerInput.cid),
aq.callerInput.options ?? {}
);
for await (const chunk of iterable) {
if (aborted) {
@ -304,25 +313,24 @@ async function handleIpnsResolve(aq: ActiveQuery) {
await activePeersDefer.promise;
if (PeerManager.instance.ipfs.libp2p.getPeers().length === 0) {
activePeersDefer = defer();
}
await activePeersDefer.promise;
if (!aq.callerInput || !("cid" in aq.callerInput)) {
aq.reject("cid required");
return;
}
const prefix = substr(aq.callerInput.cid, 0, 1);
if (!(prefix in basesByPrefix)) {
aq.reject("invalid multibase found in CID");
return;
}
const base = basesByPrefix[prefix];
const cid = CID.parse(aq.callerInput.cid, base);
try {
return aq.respond(
(
await IPNS.resolve(peerIdFromCID(cid), aq.callerInput?.options)
await IPNS.resolve(
peerIdFromCID(getCID(aq.callerInput.cid)),
aq.callerInput?.options
)
).asCID.toString()
);
} catch (e: any) {
@ -330,6 +338,17 @@ async function handleIpnsResolve(aq: ActiveQuery) {
}
}
function getCID(cid: string): CID {
const prefix = substr(cid, 0, 1);
if (!(prefix in basesByPrefix)) {
throw new Error("invalid multibase found in CID");
}
const base = basesByPrefix[prefix];
return CID.parse(cid, base);
}
async function handleGetActivePeers(aq: ActiveQuery) {
await ready();