From b955dba9a4596aa22ba90b1f7b2e5459fd9cbe85 Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Tue, 14 Nov 2023 17:08:40 +0000 Subject: [PATCH 1/2] 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 https://github.com/web3-storage/www/pull/22 License: MIT Signed-off-by: Oli Evans --- packages/w3up-client/example/upload.js | 36 ++++++++++++++++++++++++++ packages/w3up-client/package.json | 3 ++- pnpm-lock.yaml | 12 ++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 packages/w3up-client/example/upload.js diff --git a/packages/w3up-client/example/upload.js b/packages/w3up-client/example/upload.js new file mode 100644 index 000000000..e4cd8c2c3 --- /dev/null +++ b/packages/w3up-client/example/upload.js @@ -0,0 +1,36 @@ +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() + +// 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!') diff --git a/packages/w3up-client/package.json b/packages/w3up-client/package.json index eb7039d8b..ecbbe15b8 100644 --- a/packages/w3up-client/package.json +++ b/packages/w3up-client/package.json @@ -107,7 +107,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", @@ -116,9 +115,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 f6f92e6dc..010c1ceb9 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'} From 119eda643607ca833c3901a296eeadc24ee66582 Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 15 Nov 2023 11:12:09 +0000 Subject: [PATCH 2/2] chore: tweak logging License: MIT Signed-off-by: Oli Evans --- packages/w3up-client/example/upload.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/w3up-client/example/upload.js b/packages/w3up-client/example/upload.js index e4cd8c2c3..ef5aac0d4 100644 --- a/packages/w3up-client/example/upload.js +++ b/packages/w3up-client/example/upload.js @@ -11,17 +11,22 @@ 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. Plz check your inbox', email) + console.log('💌 sending a verification link to', email) const account = await client.login(email) // create a space for your uploads - const space = await client.createSpace(spaceName) - + 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()) } @@ -32,5 +37,5 @@ 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!')