-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstorePageData.js
More file actions
33 lines (30 loc) · 949 Bytes
/
storePageData.js
File metadata and controls
33 lines (30 loc) · 949 Bytes
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
/// checked and approved
// customized to store a json file created from the data we enter
import { Web3Storage } from "web3.storage";
import { WEB3STORAGE_TOKEN } from "../constants/constants";
function getAccessToken() {
return WEB3STORAGE_TOKEN;
}
function MakeStorageClient() {
return new Web3Storage({ token: getAccessToken() });
}
export const StorePageData = async (
pageName,
pageDescription,
domainName,
contactDetails
) => {
const obj = {
PageName: pageName,
PageDescription: pageDescription,
Domain: domainName,
Contact: contactDetails,
};
const blob = new Blob([JSON.stringify(obj)], { type: "application/json" });
const files = [new File([blob], "request.json")];
console.log("Uploading data to IPFS with web3.storage....");
const client = MakeStorageClient();
const cid = await client.put(files, { wrapWithDirectory: false });
console.log("Stored files with cid:", cid);
return cid;
};