From 63d21250f9d6dc08d40f615e5cd341c08d5e3b50 Mon Sep 17 00:00:00 2001 From: dirkmc Date: Wed, 10 Jul 2019 04:59:17 -0400 Subject: [PATCH] GC endpoint (#992) * feat: gc * fix: better repo.gc() response handling * fix: repo.gc() cid handling * chore: update interface-ipfs-core --- package.json | 2 +- src/repo/gc.js | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d9b58aa83..cdd0ff456 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "cross-env": "^5.2.0", "dirty-chai": "^2.0.1", "go-ipfs-dep": "~0.4.21", - "interface-ipfs-core": "~0.105.0", + "interface-ipfs-core": "~0.106.0", "ipfsd-ctl": "~0.43.0", "nock": "^10.0.2", "stream-equal": "^1.1.1" diff --git a/src/repo/gc.js b/src/repo/gc.js index 27a9d3ca8..35d4288b0 100644 --- a/src/repo/gc.js +++ b/src/repo/gc.js @@ -1,6 +1,15 @@ 'use strict' const promisify = require('promisify-es6') +const streamToValueWithTransformer = require('../utils/stream-to-value-with-transformer') +const CID = require('cids') + +const transform = function (res, callback) { + callback(null, res.map(r => ({ + err: r.Err ? new Error(r.Err) : null, + cid: (r.Key || {})['/'] ? new CID(r.Key['/']) : null + }))) +} module.exports = (send) => { return promisify((opts, callback) => { @@ -8,9 +17,17 @@ module.exports = (send) => { callback = opts opts = {} } - send({ + + const request = { path: 'repo/gc', qs: opts - }, callback) + } + send(request, (err, result) => { + if (err) { + return callback(err) + } + + streamToValueWithTransformer(result, transform, callback) + }) }) }