Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d89ce96

Browse files
committed
feat(bitswap.unwant) expose bitswap.unwant to cli and http api
1 parent de95989 commit d89ce96

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

src/cli/commands/bitswap/unwant.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
'use strict'
22

3+
const print = require('../../utils').print
4+
35
module.exports = {
46
command: 'unwant <key>',
57

6-
describe: 'Remove a given block from your wantlist.',
8+
describe: 'Removes a given block from your wantlist.',
79

10+
builder: {
11+
key: {
12+
alias: 'k',
13+
describe: 'Key to remove from your wantlist',
14+
type: 'string'
15+
}
16+
},
817
handler (argv) {
9-
throw new Error('Not implemented yet')
18+
argv.ipfs.bitswap.unwant(argv.key)
19+
print(`Key ${argv.key} removed from wantlist`)
1020
}
1121
}

src/core/components/bitswap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = function bitswap (self) {
4545
throw new Error(OFFLINE_ERROR)
4646
}
4747

48-
// TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged
48+
self._bitswap.unwant(key)
4949
}
5050
}
5151
}

src/http/api/resources/bitswap.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ exports.stat = (request, reply) => {
4646
}
4747

4848
exports.unwant = {
49-
// uses common parseKey method that returns a `key`
49+
// uses common parseKey method that assigns a `key` to request.pre.args
5050
parseArgs: parseKey,
5151

52+
// main route handler which is called after the above `parseArgs`, but only if the args were valid
5253
handler: (request, reply) => {
53-
reply(boom.badRequest(new Error('Not implemented yet')))
54+
const key = request.pre.args.key
55+
const ipfs = request.server.app.ipfs
56+
try {
57+
ipfs.bitswap.unwant(key)
58+
} catch (err) {
59+
return reply(boom.badRequest(err))
60+
}
61+
62+
reply({ Key: key })
5463
}
5564
}

test/cli/bitswap.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ describe('bitswap', () => runOn((thing) => {
2323
})
2424
})
2525

26-
// TODO @hacdias fix this with https://github.com/ipfs/js-ipfs/pull/1198
27-
it.skip('stat', function () {
26+
it('stat', function () {
2827
this.timeout(20 * 1000)
2928

3029
return ipfs('bitswap stat').then((out) => {
@@ -40,4 +39,10 @@ describe('bitswap', () => runOn((thing) => {
4039
].join('\n') + '\n')
4140
})
4241
})
42+
43+
it('unwant', function () {
44+
return ipfs('bitswap unwant ' + key).then((out) => {
45+
expect(out).to.eql(`Key ${key} removed from wantlist\n`)
46+
})
47+
})
4348
}))

test/core/bitswap.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ skipOnWindows('bitswap', function () {
283283
})
284284
})
285285

286-
it('throws if offline', () => {
286+
it('.unwant throws if offline', () => {
287287
expect(() => node.bitswap.unwant('my key')).to.throw(/online/)
288288
})
289289
})

0 commit comments

Comments
 (0)