-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add minimal w3up upload example
trying to find a nice minimal example that folks can run and re-run to try thing out. pulled from storacha/www#22 License: MIT Signed-off-by: Oli Evans <oli@protocol.ai>
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as Client from '../src/index.node.js' | ||
import { filesFromPaths } from 'files-from-path' | ||
|
||
/** | ||
* Usage: | ||
* node upload.js <email> <space name> <path> | ||
*/ | ||
const [,,email, spaceName, path] = process.argv | ||
|
||
console.log({email, spaceName, path}) | ||
|
||
const client = await Client.create() | ||
|
||
// first time setup! | ||
if (!client.accounts().length) { | ||
// waits for you to click the link in your email to verify your identity | ||
console.log('💌 Sending a verification link. Plz check your inbox', email) | ||
const account = await client.login(email) | ||
|
||
// create a space for your uploads | ||
const space = await client.createSpace(spaceName) | ||
|
||
await space.save() | ||
|
||
// associate this space with your account | ||
await account.provision(space.did()) | ||
} | ||
|
||
// content-address your files | ||
const files = await filesFromPaths([path]) | ||
console.log('🚀 uploading', path) | ||
const root = await client.uploadDirectory(files) | ||
|
||
console.log('root', root.toString()) | ||
console.log('space', space.did(), space.name()) | ||
console.log('done!') |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.