This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 5 files changed +32
-8
lines changed
5 files changed +32
-8
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ const print = require ( '../../utils' ) . print
4
+
3
5
module . exports = {
4
6
command : 'unwant <key>' ,
5
7
6
- describe : 'Remove a given block from your wantlist.' ,
8
+ describe : 'Removes a given block from your wantlist.' ,
7
9
10
+ builder : {
11
+ key : {
12
+ alias : 'k' ,
13
+ describe : 'Key to remove from your wantlist' ,
14
+ type : 'string'
15
+ }
16
+ } ,
8
17
handler ( argv ) {
9
- throw new Error ( 'Not implemented yet' )
18
+ argv . ipfs . bitswap . unwant ( argv . key )
19
+ print ( `Key ${ argv . key } removed from wantlist` )
10
20
}
11
21
}
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ module.exports = function bitswap (self) {
45
45
throw new Error ( OFFLINE_ERROR )
46
46
}
47
47
48
- // TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged
48
+ self . _bitswap . unwant ( key )
49
49
}
50
50
}
51
51
}
Original file line number Diff line number Diff line change @@ -46,10 +46,19 @@ exports.stat = (request, reply) => {
46
46
}
47
47
48
48
exports . unwant = {
49
- // uses common parseKey method that returns a `key`
49
+ // uses common parseKey method that assigns a `key` to request.pre.args
50
50
parseArgs : parseKey ,
51
51
52
+ // main route handler which is called after the above `parseArgs`, but only if the args were valid
52
53
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 } )
54
63
}
55
64
}
Original file line number Diff line number Diff line change @@ -23,8 +23,7 @@ describe('bitswap', () => runOn((thing) => {
23
23
} )
24
24
} )
25
25
26
- // TODO @hacdias fix this with https://github.com/ipfs/js-ipfs/pull/1198
27
- it . skip ( 'stat' , function ( ) {
26
+ it ( 'stat' , function ( ) {
28
27
this . timeout ( 20 * 1000 )
29
28
30
29
return ipfs ( 'bitswap stat' ) . then ( ( out ) => {
@@ -40,4 +39,10 @@ describe('bitswap', () => runOn((thing) => {
40
39
] . join ( '\n' ) + '\n' )
41
40
} )
42
41
} )
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
+ } )
43
48
} ) )
Original file line number Diff line number Diff line change @@ -283,7 +283,7 @@ skipOnWindows('bitswap', function () {
283
283
} )
284
284
} )
285
285
286
- it ( 'throws if offline' , ( ) => {
286
+ it ( '.unwant throws if offline' , ( ) => {
287
287
expect ( ( ) => node . bitswap . unwant ( 'my key' ) ) . to . throw ( / o n l i n e / )
288
288
} )
289
289
} )
You can’t perform that action at this time.
0 commit comments