diff --git a/packages/w3up-client/example/upload.js b/packages/w3up-client/example/upload.js new file mode 100644 index 000000000..ef5aac0d4 --- /dev/null +++ b/packages/w3up-client/example/upload.js @@ -0,0 +1,41 @@ +import * as Client from '../src/index.node.js' +import { filesFromPaths } from 'files-from-path' + +/** + * Usage: + * node upload.js + */ +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!') diff --git a/packages/w3up-client/package.json b/packages/w3up-client/package.json index 678c03b85..d980d3ece 100644 --- a/packages/w3up-client/package.json +++ b/packages/w3up-client/package.json @@ -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", @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 645e9399f..cbc5cb7c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -595,6 +595,9 @@ importers: docusaurus-plugin-typedoc: specifier: ^0.18.0 version: 0.18.0(typedoc-plugin-markdown@3.17.0)(typedoc@0.23.28) + files-from-path: + specifier: ^1.0.1 + version: 1.0.1 hundreds: specifier: ^0.0.9 version: 0.0.9 @@ -5861,6 +5864,13 @@ packages: webpack: 5.89.0 dev: true + /files-from-path@1.0.1: + resolution: {integrity: sha512-laySl80uFX+VkIo86FnvzG1mAdfea/arDrO3JBelF8sEJmWUr2rnQs6ntrqZ+5zEnmXTZNg4gMFWC8NmLCys/g==} + engines: {node: '>=18'} + dependencies: + graceful-fs: 4.2.11 + dev: true + /filesize@8.0.7: resolution: {integrity: sha512-pjmC+bkIF8XI7fWaH8KxHcZL3DPybs1roSKP4rKDvy20tAWwIObE4+JIseG2byfGKhud5ZnM4YSGKBz7Sh0ndQ==} engines: {node: '>= 0.4.0'}