|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -const promisify = require('promisify-es6') |
| 3 | +const configure = require('../lib/configure') |
4 | 4 |
|
5 | | -module.exports = (send) => { |
6 | | - return promisify((hash, opts, callback) => { |
7 | | - if (typeof hash === 'function') { |
8 | | - callback = hash |
9 | | - opts = null |
10 | | - hash = null |
| 5 | +module.exports = configure(({ ky }) => { |
| 6 | + return async (path, options) => { |
| 7 | + if (path && path.type) { |
| 8 | + options = path |
| 9 | + path = null |
11 | 10 | } |
12 | | - if (typeof opts === 'function') { |
13 | | - callback = opts |
14 | | - opts = null |
15 | | - } |
16 | | - if (hash && hash.type) { |
17 | | - opts = hash |
18 | | - hash = null |
19 | | - } |
20 | | - send({ |
21 | | - path: 'pin/ls', |
22 | | - args: hash, |
23 | | - qs: opts |
24 | | - }, (err, res) => { |
25 | | - if (err) { |
26 | | - return callback(err) |
27 | | - } |
28 | | - callback(null, Object.keys(res.Keys).map(hash => ( |
29 | | - { hash, type: res.Keys[hash].Type } |
30 | | - ))) |
31 | | - }) |
32 | | - }) |
33 | | -} |
| 11 | + |
| 12 | + options = options || {} |
| 13 | + |
| 14 | + const searchParams = new URLSearchParams(options.searchParams) |
| 15 | + if (path) searchParams.set('arg', `${path}`) |
| 16 | + if (options.type) searchParams.set('type', options.type) |
| 17 | + |
| 18 | + const { Keys } = await ky.get('pin/ls', { |
| 19 | + timeout: options.timeout, |
| 20 | + signal: options.signal, |
| 21 | + headers: options.headers, |
| 22 | + searchParams |
| 23 | + }).json() |
| 24 | + |
| 25 | + return Object.keys(Keys).map(hash => ({ hash, type: Keys[hash].Type })) |
| 26 | + } |
| 27 | +}) |
0 commit comments