diff --git a/src/bootstrap/add.js b/src/bootstrap/add.js index 978a3eedad..29dd46cc3e 100644 --- a/src/bootstrap/add.js +++ b/src/bootstrap/add.js @@ -1,32 +1,28 @@ 'use strict' -const promisify = require('promisify-es6') +const Multiaddr = require('multiaddr') +const configure = require('../lib/configure') -module.exports = (send) => { - return promisify((args, opts, callback) => { - if (typeof opts === 'function' && - !callback) { - callback = opts - opts = {} +module.exports = configure(({ ky }) => { + return async (addr, options) => { + if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) { + options = addr + addr = null } - // opts is the real callback -- - // 'callback' is being injected by promisify - if (typeof opts === 'function' && - typeof callback === 'function') { - callback = opts - opts = {} - } + options = options || {} - if (args && typeof args === 'object') { - opts = args - args = undefined - } + const searchParams = new URLSearchParams(options.searchParams) + if (addr) searchParams.set('arg', `${addr}`) + if (options.default != null) searchParams.set('default', options.default) + + const res = await ky.post('bootstrap/add', { + timeout: options.timeout, + signal: options.signal, + headers: options.headers, + searchParams + }).json() - send({ - path: 'bootstrap/add', - args: args, - qs: opts - }, callback) - }) -} + return res + } +}) diff --git a/src/bootstrap/index.js b/src/bootstrap/index.js index 31cb3fa2f5..0322658031 100644 --- a/src/bootstrap/index.js +++ b/src/bootstrap/index.js @@ -1,13 +1,9 @@ 'use strict' -const moduleConfig = require('../utils/module-config') +const callbackify = require('callbackify') -module.exports = (arg) => { - const send = moduleConfig(arg) - - return { - add: require('./add')(send), - rm: require('./rm')(send), - list: require('./list')(send) - } -} +module.exports = config => ({ + add: callbackify.variadic(require('./add')(config)), + rm: callbackify.variadic(require('./rm')(config)), + list: callbackify.variadic(require('./list')(config)) +}) diff --git a/src/bootstrap/list.js b/src/bootstrap/list.js index 79690ef191..2a20f5d053 100644 --- a/src/bootstrap/list.js +++ b/src/bootstrap/list.js @@ -1,16 +1,18 @@ 'use strict' -const promisify = require('promisify-es6') +const configure = require('../lib/configure') -module.exports = (send) => { - return promisify((opts, callback) => { - if (typeof (opts) === 'function') { - callback = opts - opts = {} - } - send({ - path: 'bootstrap/list', - qs: opts - }, callback) - }) -} +module.exports = configure(({ ky }) => { + return async (options) => { + options = options || {} + + const res = await ky.get('bootstrap/list', { + timeout: options.timeout, + signal: options.signal, + headers: options.headers, + searchParams: options.searchParams + }).json() + + return res + } +}) diff --git a/src/bootstrap/rm.js b/src/bootstrap/rm.js index c7f55368b5..4c2597d1d2 100644 --- a/src/bootstrap/rm.js +++ b/src/bootstrap/rm.js @@ -1,32 +1,28 @@ 'use strict' -const promisify = require('promisify-es6') +const Multiaddr = require('multiaddr') +const configure = require('../lib/configure') -module.exports = (send) => { - return promisify((args, opts, callback) => { - if (typeof opts === 'function' && - !callback) { - callback = opts - opts = {} +module.exports = configure(({ ky }) => { + return async (addr, options) => { + if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) { + options = addr + addr = null } - // opts is the real callback -- - // 'callback' is being injected by promisify - if (typeof opts === 'function' && - typeof callback === 'function') { - callback = opts - opts = {} - } + options = options || {} - if (args && typeof args === 'object') { - opts = args - args = undefined - } + const searchParams = new URLSearchParams(options.searchParams) + if (addr) searchParams.set('arg', `${addr}`) + if (options.all != null) searchParams.set('all', options.all) + + const res = await ky.post('bootstrap/rm', { + timeout: options.timeout, + signal: options.signal, + headers: options.headers, + searchParams + }).json() - send({ - path: 'bootstrap/rm', - args: args, - qs: opts - }, callback) - }) -} + return res + } +}) diff --git a/src/utils/load-commands.js b/src/utils/load-commands.js index 242b52463a..9e9db2cf5d 100644 --- a/src/utils/load-commands.js +++ b/src/utils/load-commands.js @@ -91,6 +91,7 @@ function requireCommands (send, config) { getEndpointConfig: require('../get-endpoint-config')(config), bitswap: require('../bitswap')(config), block: require('../block')(config), + bootstrap: require('../bootstrap')(config), dag: require('../dag')(config) } @@ -110,7 +111,6 @@ function requireCommands (send, config) { pin: require('../pin'), // Network - bootstrap: require('../bootstrap'), dht: require('../dht'), name: require('../name'), ping: require('../ping'),