This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +37
-9
lines changed Expand file tree Collapse file tree 4 files changed +37
-9
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 , ( err , res ) => {
19
+ if ( err ) {
20
+ throw err
21
+ }
22
+ print ( `Key ${ argv . key } removed from wantlist` )
23
+ } )
10
24
}
11
25
}
Original file line number Diff line number Diff line change @@ -40,12 +40,12 @@ module.exports = function bitswap (self) {
40
40
} )
41
41
} ) ,
42
42
43
- unwant : ( key ) => {
43
+ unwant : promisify ( ( key , callback ) => {
44
44
if ( ! self . isOnline ( ) ) {
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
49
- }
48
+ return self . _bitswap . unwant ( key )
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
} ) )
You can’t perform that action at this time.
0 commit comments