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

fix: use remove from client #167

Merged
merged 1 commit into from
Jan 25, 2024
Merged
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
35 changes: 2 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,45 +204,14 @@
process.exit(1)
}
const client = await getClient()
let upload

try {
upload = await client.capability.upload.remove(root)
await client.remove(root, opts)
} catch (/** @type {any} */ err) {
console.error(`Remove failed: ${err.message ?? err}`)
console.error(err)
process.exit(1)
}
if (!opts.shards) {
return
}
if (!upload.root) {
return console.log(
'⁂ upload not found. could not determine shards to remove.'
)
}
if (!upload.shards || !upload.shards.length) {
return console.log('⁂ no shards to remove.')
}

const { shards } = upload
console.log(
`⁂ removing ${shards.length} shard${shards.length === 1 ? '' : 's'}`
)

/** @param {import('@web3-storage/w3up-client/types').CARLink} shard */
function removeShard(shard) {
return oraPromise(client.capability.store.remove(shard), {
text: `${shard}`,
successText: `${shard} removed`,
failText: `${shard} failed`,
})
}

const results = await Promise.allSettled(shards.map(removeShard))

if (results.some((res) => res.status === 'rejected')) {
process.exit(1)
}
}

/**
Expand Down Expand Up @@ -568,7 +537,7 @@
}
}

export async function whoami() {

Check warning on line 540 in index.js

View workflow job for this annotation

GitHub Actions / Test

Missing JSDoc comment
const client = await getClient()
console.log(client.did())
}
Expand Down
90 changes: 79 additions & 11 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@web3-storage/access": "^18.0.7",
"@web3-storage/data-segment": "^5.0.0",
"@web3-storage/did-mailto": "^2.1.0",
"@web3-storage/w3up-client": "^11.2.1",
"@web3-storage/w3up-client": "^12.2.0",
"ansi-escapes": "^6.2.0",
"chalk": "^5.3.0",
"files-from-path": "^1.0.4",
Expand Down
61 changes: 3 additions & 58 deletions test/bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,69 +774,14 @@ export const testW3Up = {
])
.env(context.env.alice)
.join()
.catch()

assert.equal(rm.status.code, 0)
assert.match(
rm.output,
/upload not found. could not determine shards to remove/
)
}),

'w3 remove --shards': test(async (assert, context) => {
await loginAndCreateSpace(context)

const up = await w3
.args(['up', 'test/fixtures/pinpie.jpg'])
.env(context.env.alice)
.join()

assert.match(
up.output,
/bafybeiajdopsmspomlrpaohtzo5sdnpknbolqjpde6huzrsejqmvijrcea/
)

const rm = await w3
.args([
'rm',
'bafybeiajdopsmspomlrpaohtzo5sdnpknbolqjpde6huzrsejqmvijrcea',
'--shards',
])
.env(context.env.alice)
.join()

assert.equal(rm.status.code, 0)

assert.match(rm.output, /1 shard/)
assert.equal(rm.status.code, 1)
assert.match(
rm.error,
/bagbaieraxkuzouwfuphnqlbbpobywmypb26stej5vbwkelrv7chdqoxfuuea removed/
/Upload not found/
)
}),

'w3 remove --shards - no shards to remove': test(async (assert, context) => {
const space = await loginAndCreateSpace(context)

const root = parseLink(
'bafybeih2k7ughhfwedltjviunmn3esueijz34snyay77zmsml5w24tqamm'
)

// store upload without any shards
await context.uploadTable.insert({
space,
root,
shards: [],
issuer: Test.alice.did(),
invocation: parseLink('bafkqaaa'),
})

const rm = await w3
.args(['rm', root.toString(), '--shards'])
.env(context.env.alice)
.join()

assert.equal(rm.status.code, 0)
assert.match(rm.output, /no shards to remove/)
}),
}

export const testDelegation = {
Expand Down