-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: switch browser car demo to use vite
as skypack is not work, see: storacha/ipfs-car#27 License: MIT Signed-off-by: Oli Evans <oli@tableflip.io>
- Loading branch information
Showing
7 changed files
with
91 additions
and
45 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
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,16 @@ | ||
# CAR upload demo - nft.storage | ||
|
||
A demo using ipfs-car in the browser to create a CAR file and pre-calculate the CID for an asset then storing it on nft.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 nft.upload 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,35 @@ | ||
import { NFTStorage } from 'nft.storage' | ||
import { packToBlob } from 'ipfs-car/pack/blob' | ||
|
||
const endpoint = 'http://api.nft.storage' // the default | ||
const token = | ||
new URLSearchParams(window.location.search).get('key') || 'API_KEY' // your API key from https://nft.storage/manage | ||
|
||
function log(msg) { | ||
msg = JSON.stringify(msg, null, 2) | ||
document.getElementById('out').innerHTML += `${msg}\n` | ||
} | ||
|
||
async function main() { | ||
const store = new NFTStorage({ endpoint, token }) | ||
const data = 'Hello nft.storage!' | ||
|
||
// locally chunk'n'hash the data to get the CID and pack the blocks in to a CAR | ||
const { root, car } = await packToBlob({ | ||
input: [new TextEncoder().encode(data)], | ||
}) | ||
const expectedCid = root.toString() | ||
console.log({ expectedCid }) | ||
|
||
// send the CAR to nft.storage, the returned CID will match the one we created above. | ||
const cid = await store.storeCar(car) | ||
|
||
// verify the service is storing the CID we expect | ||
const cidsMatch = expectedCid === cid | ||
log({ data, cid, expectedCid, cidsMatch }) | ||
|
||
// check that the CID is pinned | ||
const status = await store.status(cid) | ||
log(status) | ||
} | ||
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,15 @@ | ||
{ | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"serve": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"vite": "^2.3.7" | ||
}, | ||
"dependencies": { | ||
"ipfs-car": "^0.2.4", | ||
"nft.storage": "../../../" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.