Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add minimal w3up upload example #1126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/w3up-client/example/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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()

let space

// 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 to', email)
const account = await client.login(email)

// create a space for your uploads
space = await client.createSpace(spaceName)
console.log('✨ created space', space.did(), space.name)

console.log('💾 saving space')
await space.save()

console.log('💳 provisioning space')
// 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('done!')
3 changes: 2 additions & 1 deletion packages/w3up-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
"@web3-storage/upload-client": "workspace:^"
},
"devDependencies": {
"@web3-storage/upload-api": "workspace:^",
"@docusaurus/core": "^2.2.0",
"@ipld/car": "^5.1.1",
"@types/assert": "^1.5.6",
Expand All @@ -117,9 +116,11 @@
"@ucanto/server": "^9.0.1",
"@web3-storage/data-segment": "^5.0.0",
"@web3-storage/eslint-config-w3up": "workspace:^",
"@web3-storage/upload-api": "workspace:^",
"assert": "^2.0.0",
"c8": "^7.13.0",
"docusaurus-plugin-typedoc": "^0.18.0",
"files-from-path": "^1.0.1",
"hundreds": "^0.0.9",
"mocha": "^10.1.0",
"multiformats": "^12.1.2",
Expand Down
12 changes: 11 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading