Skip to content

Commit 1547922

Browse files
committed
Update deploy-ipfs to use nifty ink
1 parent 470f9c1 commit 1547922

File tree

3 files changed

+715
-64
lines changed

3 files changed

+715
-64
lines changed

packages/nextjs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"blo": "^1.2.0",
2424
"burner-connector": "0.0.9",
2525
"daisyui": "4.12.10",
26+
"kubo-rpc-client": "^5.0.2",
2627
"next": "^14.2.11",
2728
"next-nprogress-bar": "^2.3.13",
2829
"next-themes": "^0.3.0",

packages/nextjs/scripts/deploy-ipfs.js

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,61 @@
1-
import { exec } from "child_process";
1+
import { create } from "kubo-rpc-client";
2+
import { globSource } from "kubo-rpc-client";
23
import { dirname, join } from "path";
34
import { fileURLToPath } from "url";
4-
import { promisify } from "util";
55

6-
const execAsync = promisify(exec);
76
const __filename = fileURLToPath(import.meta.url);
87
const __dirname = dirname(__filename);
98

10-
async function checkIpfsDaemon() {
9+
const ipfsConfig = {
10+
host: "ipfs.nifty.ink",
11+
port: 3001,
12+
protocol: "https",
13+
timeout: 250000,
14+
};
15+
16+
async function addDirectoryToIpfs(path) {
17+
console.log("📦 Adding directory to IPFS via Nifty Ink...");
18+
1119
try {
12-
await execAsync("ipfs --version");
13-
// Check if daemon is running and has peers
14-
const { stdout } = await execAsync("ipfs swarm peers");
15-
const peerCount = stdout.split("\n").filter(Boolean).length;
20+
const ipfs = create(ipfsConfig);
21+
22+
// Track the root directory CID
23+
let rootCid = null;
1624

17-
if (peerCount < 1) {
18-
console.log("⚠️ Warning: Your IPFS node has no peers. Content might not be accessible immediately.");
19-
console.log("Waiting for peers to connect...");
20-
// Wait for peers to connect
21-
await new Promise(resolve => setTimeout(resolve, 10000));
22-
const { stdout: newStdout } = await execAsync("ipfs swarm peers");
23-
const newPeerCount = newStdout.split("\n").filter(Boolean).length;
24-
if (newPeerCount < 1) {
25-
console.log("Still no peers connected. You might want to:");
26-
console.log("1. Check your internet connection");
27-
console.log("2. Ensure your IPFS daemon is not behind a firewall");
28-
console.log("3. Try running 'ipfs daemon --enable-pubsub-experiment' for better connectivity");
25+
// Add the entire directory to IPFS
26+
for await (const result of ipfs.addAll(globSource(path, "**/*"), {
27+
pin: true,
28+
wrapWithDirectory: true, // This is key - it wraps all files in a directory
29+
})) {
30+
if (result.path === "") {
31+
// This is the root directory entry
32+
rootCid = result.cid;
2933
} else {
30-
console.log(`✓ Connected to ${newPeerCount} peers`);
34+
console.log(`Added ${result.path} - CID: ${result.cid}`);
3135
}
32-
} else {
33-
console.log(`✓ Connected to ${peerCount} peers`);
3436
}
35-
} catch (error) {
36-
console.log(error);
37-
console.error("❌ IPFS is not installed or daemon is not running.");
38-
console.log("Please install IPFS and start the daemon:");
39-
console.log("1. Install IPFS: https://docs.ipfs.tech/install/");
40-
console.log("2. Start the daemon: ipfs daemon");
41-
process.exit(1);
42-
}
43-
}
4437

45-
async function addDirectoryToIpfs(path) {
46-
console.log("📦 Adding directory to IPFS...");
47-
48-
try {
49-
// Add the entire directory to IPFS and get the hash
50-
const { stdout } = await execAsync(`ipfs add -r -Q "${path}"`);
51-
const cid = stdout.trim();
52-
53-
// Announce the content to the network
54-
try {
55-
await execAsync(`ipfs dht provide ${cid}`);
56-
console.log("✓ Announced content to the IPFS network");
57-
} catch (error) {
58-
console.log(error);
59-
console.log("⚠️ Warning: Could not announce content to the network. Content might take longer to be available.");
38+
if (!rootCid) {
39+
throw new Error("Failed to get root directory CID");
6040
}
6141

62-
return cid;
42+
return rootCid.toString();
6343
} catch (error) {
6444
console.error("Error adding directory to IPFS:", error);
6545
throw error;
6646
}
6747
}
6848

6949
async function main() {
70-
// First check if IPFS is installed and running
71-
await checkIpfsDaemon();
72-
7350
// Get the path to the out directory
7451
const outDir = join(__dirname, "..", "out");
7552

76-
console.log("🚀 Uploading to IPFS...");
53+
console.log("🚀 Uploading to Nifty Ink IPFS...");
7754
const cid = await addDirectoryToIpfs(outDir);
7855

79-
// Give the network some time to propagate the content
80-
console.log("\n⏳ Waiting for network propagation...");
81-
await new Promise(resolve => setTimeout(resolve, 5000));
82-
8356
console.log("\n✨ Upload complete! Your site is now available at:");
84-
console.log(`🔗 IPFS Gateway: https://ipfs.io/ipfs/${cid}`);
85-
console.log("\n💡 To ensure your site stays available:");
86-
console.log("1. Keep your IPFS daemon running");
87-
console.log("2. Pin the CID on other nodes: ipfs pin add " + cid);
88-
console.log("\n💡 If the gateway times out, you can:");
89-
console.log("1. Wait a few minutes and try again");
90-
console.log("2. Install the IPFS Companion browser extension");
57+
console.log(`🔗 Nifty Ink Gateway: https://gateway.nifty.ink:42069/ipfs/${cid}`);
58+
console.log("\n💡 Note: Your content is being served through the Nifty Ink IPFS gateway");
9159
}
9260

9361
main().catch(err => {

0 commit comments

Comments
 (0)