-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9eae4a4
commit 3e5bb9d
Showing
19 changed files
with
1,159 additions
and
738 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Files demo browser - web3.storage | ||
|
||
🚧 **WORK IN PROGRESS** 🚧 | ||
|
||
A demo using web3.storage client in the browser to pre-calculate the CID for an asset then storing it on tbd.storage and confirming that it uses the exact same CID for the asset. | ||
|
||
## Getting started | ||
|
||
```console | ||
npm install | ||
npm run dev | ||
|
||
# or | ||
yarn | ||
yarn dev | ||
``` | ||
|
||
Then visit `http://localhost:3000?key=<your web3.storage API KEY here>` |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>CAR upload - nft.storage</title> | ||
</head> | ||
<body> | ||
<pre id="out"></pre> | ||
<script type="module" src="/main.js"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Web3Storage } from 'web3.storage' | ||
import { Web3File } from 'web3-file' | ||
|
||
const endpoint = 'https://api.web3.storage' // the default | ||
const token = | ||
new URLSearchParams(window.location.search).get('key') || 'API_KEY' // your API key from https://web3.storage/manage | ||
|
||
async function main() { | ||
const storage = new Web3Storage({ endpoint, token }) | ||
|
||
const files = prepareFiles() | ||
|
||
// send the files to tbd.storage | ||
const cid = await storage.put(files) | ||
|
||
// TODO | ||
console.log('added', cid) | ||
// check that the CID is pinned | ||
// const status = await store.status(cid) | ||
// log(status) | ||
} | ||
|
||
function prepareFiles () { | ||
const data = 'Hello web3.storage!' | ||
const data2 = 'Hello web3.storage!!' | ||
|
||
return [ | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data), | ||
'data.zip', | ||
{ path: '/dir/data.zip' } | ||
), | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data2), | ||
'data2.zip', | ||
{ path: '/dir/data2.zip' } | ||
), | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data), | ||
'data.zip', | ||
{ path: '/dir/dir/data.zip' } | ||
), | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data2), | ||
'data2.zip', | ||
{ path: '/dir/dir/data2.zip' } | ||
) | ||
] | ||
} | ||
|
||
main() |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"serve": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"vite": "^2.3.7" | ||
}, | ||
"dependencies": { | ||
"web3.storage": "../../" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Files demo Node.js - web3.storage | ||
|
||
🚧 **WORK IN PROGRESS** 🚧 |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Web3Storage } from '../../src/lib.js' | ||
import { Web3File } from 'web3-file' | ||
|
||
// TODO | ||
const endpoint = 'https://api.web3.storage' // the default | ||
const token = 'API_KEY' // your API key from https://web3.storage/manage | ||
|
||
async function main() { | ||
const storage = new Web3Storage({ endpoint, token }) | ||
|
||
const files = prepareFiles() | ||
const cid = await storage.put(files) | ||
|
||
console.log('added', cid) | ||
} | ||
|
||
// TODO: Read a fixstures folder instead | ||
function prepareFiles () { | ||
const data = 'Hello web3.storage!' | ||
const data2 = 'Hello web3.storage!!' | ||
|
||
return [ | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data), | ||
'data.zip', | ||
{ path: '/dir/data.zip' } | ||
), | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data2), | ||
'data2.zip', | ||
{ path: '/dir/data2.zip' } | ||
), | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data), | ||
'data.zip', | ||
{ path: '/dir/dir/data.zip' } | ||
), | ||
Web3File.fromBytes( | ||
new TextEncoder().encode(data2), | ||
'data2.zip', | ||
{ path: '/dir/dir/data2.zip' } | ||
) | ||
] | ||
} | ||
|
||
main() |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "filecoin-storage-examples", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "Examples of using filecoin.storage in Node.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Vasco Santos", | ||
"license": "(Apache-2.0 AND MIT)" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
import fetch, { Request, Response, Headers } from '@web-std/fetch' | ||
import { Blob } from '@web-std/blob' | ||
import { File } from '@web-std/file' | ||
import { FsBlockStore as Blockstore } from 'ipfs-car/blockstore/fs' | ||
|
||
export { fetch, Request, Response, Headers, Blob } | ||
export { | ||
fetch, | ||
Request, | ||
Response, | ||
Headers, | ||
Blob, | ||
File, | ||
Blockstore | ||
} |
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,2 +1,6 @@ | ||
import { MemoryBlockStore } from 'ipfs-car/blockstore/memory' | ||
|
||
export const fetch = globalThis.fetch | ||
export const Blob = globalThis.Blob | ||
export const File = globalThis.File | ||
export const Blockstore = MemoryBlockStore |
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,5 +1,9 @@ | ||
// TODO: Use indexedDb | ||
import { MemoryBlockStore } from 'ipfs-car/blockstore/memory' | ||
|
||
export const fetch = globalThis.fetch | ||
export const Request = globalThis.Request | ||
export const Response = globalThis.Response | ||
export const Blob = globalThis.Blob | ||
export const File = globalThis.File | ||
export const Blockstore = MemoryBlockStore |
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
Oops, something went wrong.