-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from michaelg9/fixes
Fixes
- Loading branch information
Showing
9 changed files
with
93 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
WEB3_STORAGE_TOKEN= | ||
REACT_APP_WEB3_STORAGE_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
import { STORAGE_API_TOKEN } from 'variables/general'; | ||
import { STORAGE_API_TOKEN } from "variables/general"; | ||
// @ts-ignore | ||
import { Web3Storage } from 'web3.storage/dist/bundle.esm.min.js'; | ||
import { Web3Storage } from "web3.storage/dist/bundle.esm.min.js"; | ||
// import { Web3Storage, Web3File } from 'web3.storage'; | ||
|
||
const client = new Web3Storage({ token: STORAGE_API_TOKEN }) | ||
const client = new Web3Storage({ token: STORAGE_API_TOKEN }); | ||
|
||
export async function storeFilesToIPFS(filename:string, content:string) { | ||
export async function storeFilesToIPFS(filename: string, content: string) { | ||
try { | ||
const file = new File([content], filename, { type: 'text/plain' }) | ||
const file = new File([content], filename, { type: "text/plain" }); | ||
const cid = await client.put([file]); | ||
console.log(cid); | ||
|
||
// console.log(cid); | ||
return cid; | ||
} catch { | ||
|
||
} catch (e) { | ||
console.error(e); | ||
} | ||
return null; | ||
} | ||
|
||
export async function retrieveFilesFromIPFS (cid: string) { | ||
const res = await client.get(cid) | ||
if (!res || !res.ok || !res.body) return []; | ||
console.log('here'); | ||
for (const f of res.files()) { | ||
export async function retrieveFilesFromIPFS(cid: string) { | ||
const res = await client.get(cid); | ||
|
||
if (!res || !res.ok || !res.body) { | ||
console.log("Error retrieving file from IPFS"); | ||
return []; | ||
} | ||
|
||
console.log(`Got a response! [${res.status}] ${res.statusText}`); | ||
|
||
console.log("ipfs res", res); | ||
console.log("ipfs body", res.body); | ||
console.log("ipfs files", await res.files()); | ||
|
||
for (const f of await res.files()) { | ||
console.log(f); | ||
} | ||
|
||
let files = []; | ||
try { | ||
files = await res.files(); | ||
console.log(files); | ||
|
||
for (const file of files) { | ||
console.log(`${file.cid}: ${file.name} ${file.text()} (${file.size} bytes)`) | ||
console.log( | ||
`${file.cid}: ${file.name} ${file.text()} (${file.size} bytes)` | ||
); | ||
} | ||
} catch { | ||
console.log('error while fetching from IPFS'); | ||
} catch (e) { | ||
console.error("error while fetching from IPFS", e); | ||
} | ||
return files; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters