Skip to content

Instantly share code, notes, and snippets.

@meandavejustice
Created April 10, 2024 13:04
Show Gist options
  • Save meandavejustice/5247dc86e1d08250c37efa14428e2af5 to your computer and use it in GitHub Desktop.
Save meandavejustice/5247dc86e1d08250c37efa14428e2af5 to your computer and use it in GitHub Desktop.
import { create } from '@web3-storage/w3up-client'
import { filesFromPaths } from 'files-from-path'
import path from "path";
const client = await create()
const userId = 'myuserId'
async function createAndProvisionSpace(userId) {
const space = await client.createSpace(`durin-${userId}`)
const myAccount = await client.login('testingemail+w3up-test@gmail.com')
while (true) {
const res = await myAccount.plan.get()
if (res.ok) break
console.log('Waiting for payment plan to be selected...')
await new Promise(resolve => setTimeout(resolve, 1000))
}
await myAccount.provision(space.did())
await space.save()
const recovery = await space.createRecovery(myAccount.did())
await client.capability.access.delegate({
space: space.did(),
delegations: [recovery],
})
return [myAccount, space]
}
async function login() {
const myAccount = await client.login('davejustishh+w3up-test@gmail.com')
while (true) {
const res = await myAccount.plan.get()
if (res.ok) break
console.log('Waiting for payment plan to be selected...')
await new Promise(resolve => setTimeout(resolve, 1000))
}
console.log('Logged in as:', myAccount.did())
return myAccount
}
const myAccount = await login()
// await client.setCurrentSpace('did:key:z6MkmDNvDKFWrrrNRmYH6Jvq99HBKLd3sAsyp2uoFQJmcX4s')
// const [myAccount, space] = await createAndProvisionSpace(userId)
// console.log('Space:', space.did())
console.log('Account:', myAccount)
const files = await filesFromPaths(['./index.js', './package.json'])
console.log(files)
const directoryCid = await client.uploadDirectory(files)
console.log('Directory CID:', directoryCid.toString())
@meandavejustice
Copy link
Author

Uploads not showing up in web3.storage after uploadDirectory called

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment