Skip to content

Commit

Permalink
fix: not a file error durring ipfs cat
Browse files Browse the repository at this point in the history
  • Loading branch information
silkroadnomad committed Jan 21, 2025
1 parent 57fae11 commit e543df5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion relay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libp2p-relay",
"version": "0.12.42",
"version": "0.12.43",
"private": true,
"scripts": {
"start:no-restart": "node src/relay.js",
Expand Down
26 changes: 22 additions & 4 deletions relay/src/pinner/scanBlockchainForNameOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,28 @@ async function pinIpfsContent(electrumClient, helia, nameOp, nameId, ipfsUrl) {
new TextEncoder().encode('PINNING-CID:' + cid)
);

// Measure metadata size
for await (const chunk of fs.cat(CID.parse(cid))) {
metadataContent += new TextDecoder().decode(chunk);
metadataSize += chunk.length;
// Try to read as file first, fallback to directory listing
try {
// Measure metadata size
for await (const chunk of fs.cat(CID.parse(cid))) {
metadataContent += new TextDecoder().decode(chunk);
metadataSize += chunk.length;
}
} catch (error) {
if (error.code === 'ERR_NOT_A_FILE') {
// Handle directory case
console.info(`CID ${cid} is a directory, listing contents`);
for await (const entry of fs.ls(CID.parse(cid))) {
console.info(`Found directory entry: ${entry.name}`);
// Process each file in directory
for await (const chunk of fs.cat(entry.cid)) {
metadataContent += new TextDecoder().decode(chunk);
metadataSize += chunk.length;
}
}
} else {
throw error;
}
}
totalSize += metadataSize;
} catch (error) {
Expand Down

0 comments on commit e543df5

Please sign in to comment.