From 8c7be49a66c987e1b8dc2994dbb5e92d3cd22b4d Mon Sep 17 00:00:00 2001 From: Adam Stone Date: Sun, 24 Sep 2017 14:35:58 -0700 Subject: [PATCH] Make pin interface respect interface-ipfs-core API --- src/pin/add.js | 2 +- src/pin/ls.js | 24 +++++++++++++----------- src/pin/rm.js | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/pin/add.js b/src/pin/add.js index 946d32a3b..4638f5a20 100644 --- a/src/pin/add.js +++ b/src/pin/add.js @@ -16,7 +16,7 @@ module.exports = (send) => { if (err) { return callback(err) } - callback(null, res.Pins) + callback(null, res.Pins.map(hash => ({ hash }))) }) }) } diff --git a/src/pin/ls.js b/src/pin/ls.js index 5b919a673..45f6d600f 100644 --- a/src/pin/ls.js +++ b/src/pin/ls.js @@ -1,23 +1,23 @@ 'use strict' const promisify = require('promisify-es6') +const _ = require('lodash') module.exports = (send) => { return promisify((hash, opts, callback) => { + if (typeof hash === 'function') { + callback = hash + opts = null + hash = null + } if (typeof opts === 'function') { callback = opts - opts = {} } - - if (typeof hash === 'object') { + if (hash && hash.type) { opts = hash - hash = undefined - } - - if (typeof hash === 'function') { - callback = hash - hash = undefined - opts = {} + hash = null + } else { + opts = null } send({ @@ -28,7 +28,9 @@ module.exports = (send) => { if (err) { return callback(err) } - callback(null, res.Keys) + callback(null, _.keys(res.Keys).map(hash => ( + { hash, type: res.Keys[hash].Type } + ))) }) }) } diff --git a/src/pin/rm.js b/src/pin/rm.js index 82abb69ad..b7f2fcd3f 100644 --- a/src/pin/rm.js +++ b/src/pin/rm.js @@ -16,7 +16,7 @@ module.exports = (send) => { if (err) { return callback(err) } - callback(null, res.Pins) + callback(null, res.Pins.map(hash => ({ hash }))) }) }) }