-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfleekDeployIPFS.js
46 lines (39 loc) · 1021 Bytes
/
fleekDeployIPFS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require("dotenv").config();
const {
FleekSdk,
PersonalAccessTokenService,
} = require("@fleek-platform/sdk/node");
const fs = require("fs");
const accessTokenService = new PersonalAccessTokenService({
personalAccessToken: process.env.FLEEK_PAT,
projectId: process.env.FLEEK_PROJECT_ID,
});
const fleekSdk = new FleekSdk({
accessTokenService,
});
const filePath = process.argv[2];
if (!filePath) {
console.error("Usage: node fleekDeployIPFS.js <file-path>");
console.error(
"Ensure that .env contains PERSONAL_ACCESS_TOKEN and PROJECT_ID"
);
process.exit(1);
}
const uploadToIPFS = async (filePath) => {
const content = fs.readFileSync(filePath);
const fileName = filePath.split("/").pop();
const result = await fleekSdk.ipfs().add({
path: filePath,
content,
});
return result;
};
uploadToIPFS(filePath)
.then((res) => {
console.log(res.cid.toString());
process.exit(0);
})
.catch((err) => {
console.error("Upload failed:", err);
process.exit(1);
});