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

Commit

Permalink
feat(bitswap.unwant) expose bitswap.unwant to cli and http api
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Apr 12, 2018
1 parent e189b72 commit 5a46bdb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
14 changes: 12 additions & 2 deletions src/cli/commands/bitswap/unwant.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'unwant <key>',

describe: 'Remove a given block from your wantlist.',
describe: 'Removes a given block from your wantlist.',

builder: {
key: {
alias: 'k',
describe: 'Key to remove from your wantlist',
type: 'string'
}
},
handler (argv) {
throw new Error('Not implemented yet')
argv.ipfs.bitswap.unwant(argv.key)
print(`Key ${argv.key} removed from wantlist`)
}
}
2 changes: 1 addition & 1 deletion src/core/components/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = function bitswap (self) {
throw new Error(OFFLINE_ERROR)
}

// TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged
self._bitswap.unwant(key)
}
}
}
13 changes: 11 additions & 2 deletions src/http/api/resources/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ exports.stat = (request, reply) => {
}

exports.unwant = {
// uses common parseKey method that returns a `key`
// uses common parseKey method that assigns a `key` to request.pre.args
parseArgs: parseKey,

// main route handler which is called after the above `parseArgs`, but only if the args were valid
handler: (request, reply) => {
reply(boom.badRequest(new Error('Not implemented yet')))
const key = request.pre.args.key
const ipfs = request.server.app.ipfs
try {
ipfs.bitswap.unwant(key)
} catch (err) {
return reply(boom.badRequest(err))
}

reply({ Key: key })
}
}
9 changes: 7 additions & 2 deletions test/cli/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ describe('bitswap', () => runOn((thing) => {
})
})

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

return ipfs('bitswap stat').then((out) => {
Expand All @@ -40,4 +39,10 @@ describe('bitswap', () => runOn((thing) => {
].join('\n') + '\n')
})
})

it('unwant', function () {
return ipfs('bitswap unwant ' + key).then((out) => {
expect(out).to.eql(`Key ${key} removed from wantlist\n`)
})
})
}))
2 changes: 1 addition & 1 deletion test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ skipOnWindows('bitswap', function () {
})
})

it('throws if offline', () => {
it('.unwant throws if offline', () => {
expect(() => node.bitswap.unwant('my key')).to.throw(/online/)
})
})
Expand Down

0 comments on commit 5a46bdb

Please sign in to comment.