Skip to content

Commit

Permalink
feat: add index add command
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Jun 3, 2024
1 parent de3676a commit 1492185
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ w3 up recipies.txt
- UCAN-HTTP Bridge
- [`w3 bridge generate-tokens`](#w3-bridge-generate-tokens)
- Advanced usage
- [`w3 can blob add`](#w3-can-blob-add-car-path)
- [`w3 can blob add`](#w3-can-blob-add-path)
- [`w3 can blob ls`](#w3-can-blob-ls)
- [`w3 can blob rm`](#w3-can-blob-rm-car-cid)
- [`w3 can blob rm`](#w3-can-blob-rm-multihash)
- [`w3 can index add`](#w3-can-index-add-cid)
- [`w3 can space info`](#w3-can-space-info-did) <sup>coming soon!</sup>
- [`w3 can space recover`](#w3-can-space-recover-email) <sup>coming soon!</sup>
- [`w3 can upload add`](#w3-can-upload-add-root-cid-shard-cid-shard-cid)
Expand Down
6 changes: 6 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
blobAdd,
blobList,
blobRemove,
indexAdd,
storeAdd,
storeList,
storeRemove,
Expand Down Expand Up @@ -288,6 +289,11 @@ cli
.describe('Remove a blob from the store by base58btc encoded multihash.')
.action(blobRemove)

cli
.command('can index add <cid>')
.describe('Register an "index" with the service.')
.action(indexAdd)

cli
.command('can store add <car-path>')
.describe('Store a CAR file with the service.')
Expand Down
16 changes: 16 additions & 0 deletions can.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ export async function blobRemove(digestStr) {
}
}

/**
* @param {string} cidStr
*/
export async function indexAdd(cidStr) {
const client = await getClient()

const spinner = ora('Adding').start()
const cid = parseCarLink(cidStr)
if (!cid) {
spinner.fail(`Error: "${cidStr}" is not a valid index CID`)
process.exit(1)
}
await client.capability.index.add(cid)
spinner.stopAndPersist({ symbol: '⁂', text: `Added index ${cid}` })
}

/**
* @param {string} carPath
*/
Expand Down

0 comments on commit 1492185

Please sign in to comment.