Skip to content

Commit 4f4d2f7

Browse files
committed
fix: ensure handleFileUpload pins & provides root CID correctly
1 parent a121dce commit 4f4d2f7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/protocols/ipfs-handler.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ export async function createHandler(ipfsOptions, session) {
9999
rootCid = result.cid;
100100
}
101101

102+
// 1) Pin it locally so it survives any GC
103+
for await (const pinned of node.pins.add(rootCid)) {
104+
console.log("Pinned root CID:", pinned.toString());
105+
}
106+
107+
// 2) Advertise it on the DHT so others can discover it
108+
try {
109+
await node.routing.provide(rootCid);
110+
console.log("Provided CID on DHT:", rootCid.toString());
111+
} catch (err) {
112+
console.error("Error providing CID to DHT:", err);
113+
}
114+
102115
// Return URL without appending filename
103116
const fileUrl = `ipfs://${rootCid.toString()}/`;
104117

0 commit comments

Comments
 (0)