Compare commits

..

No commits in common. "3955ff2c292379ba473ed341a8d00a51fb54d839" and "fd2d66d2c4713d266b4b906e9b560310d0e9a3a1" have entirely different histories.

1 changed files with 14 additions and 33 deletions

View File

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