Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bgipfs for upload #1039

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"test": "yarn hardhat:test",
"vercel": "yarn workspace @se-2/nextjs vercel",
"vercel:yolo": "yarn workspace @se-2/nextjs vercel:yolo",
"ipfs": "yarn workspace @se-2/nextjs ipfs",
"vercel:login": "yarn workspace @se-2/nextjs vercel:login",
"verify": "yarn hardhat:verify"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ yarn-error.log*

# typescript
*.tsbuildinfo

ipfs-upload.config.json
10 changes: 10 additions & 0 deletions packages/nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ const nextConfig = {
},
};

const isIpfs = process.env.NEXT_PUBLIC_IPFS_BUILD === "true";

if (isIpfs) {
nextConfig.output = "export";
nextConfig.trailingSlash = true;
nextConfig.images = {
unoptimized: true,
};
}

module.exports = nextConfig;
6 changes: 5 additions & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"start": "next dev",
"vercel": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env VERCEL_TELEMETRY_DISABLED=1",
"vercel:yolo": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true --build-env VERCEL_TELEMETRY_DISABLED=1",
"ipfs:init": "bgipfs upload config init -u https://www.bgipfs.com/api/ipfs-proxy",
"ipfs": "NEXT_PUBLIC_IPFS_BUILD=true yarn build && yarn bgipfs upload out && echo '🚀 Upload complete! Your site is now available at: https://gateway.bgipfs.com/ipfs/${cid}'",
"vercel:login": "vercel login"
},
"dependencies": {
Expand All @@ -23,6 +25,7 @@
"blo": "^1.2.0",
"burner-connector": "0.0.9",
"daisyui": "4.12.10",
"kubo-rpc-client": "^5.0.2",
"next": "^14.2.11",
"next-nprogress-bar": "^2.3.13",
"next-themes": "^0.3.0",
Expand All @@ -42,6 +45,7 @@
"@types/react": "^18.3.5",
"abitype": "1.0.6",
"autoprefixer": "^10.4.20",
"bgipfs": "^0.0.4",
"eslint": "^8.57.1",
"eslint-config-next": "^14.2.15",
"eslint-config-prettier": "^8.10.0",
Expand All @@ -54,4 +58,4 @@
"vercel": "^39.1.3"
},
"packageManager": "[email protected]"
}
}
64 changes: 64 additions & 0 deletions packages/nextjs/scripts/deploy-ipfs.mjs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using this flie right? Lets remove it

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { create } from "kubo-rpc-client";
import { globSource } from "kubo-rpc-client";
import { dirname, join } from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const ipfsConfig = {
host: "ipfs.nifty.ink",
port: 3001,
protocol: "https",
timeout: 250000,
};

async function addDirectoryToIpfs(path) {
console.log("📦 Adding directory to IPFS via Nifty Ink...");

try {
const ipfs = create(ipfsConfig);

// Track the root directory CID
let rootCid = null;

// Add the entire directory to IPFS
for await (const result of ipfs.addAll(globSource(path, "**/*"), {
pin: true,
wrapWithDirectory: true, // This is key - it wraps all files in a directory
})) {
if (result.path === "") {
// This is the root directory entry
rootCid = result.cid;
} else {
console.log(`Added ${result.path} - CID: ${result.cid}`);
}
}

if (!rootCid) {
throw new Error("Failed to get root directory CID");
}

return rootCid.toString();
} catch (error) {
console.error("Error adding directory to IPFS:", error);
throw error;
}
}

async function main() {
// Get the path to the out directory
const outDir = join(__dirname, "..", "out");

console.log("🚀 Uploading to Nifty Ink IPFS...");
const cid = await addDirectoryToIpfs(outDir);

console.log("\n✨ Upload complete! Your site is now available at:");
console.log(`🔗 Nifty Ink Gateway: https://gateway.nifty.ink:42069/ipfs/${cid}`);
console.log("\n💡 Note: Your content is being served through the Nifty Ink IPFS gateway");
}

main().catch(err => {
console.error("Error uploading to IPFS:", err);
process.exit(1);
});
Loading