Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 63d2125

Browse files
dirkmcAlan Shaw
authored and
Alan Shaw
committed
GC endpoint (#992)
* feat: gc * fix: better repo.gc() response handling * fix: repo.gc() cid handling * chore: update interface-ipfs-core
1 parent a74b8f7 commit 63d2125

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"cross-env": "^5.2.0",
8686
"dirty-chai": "^2.0.1",
8787
"go-ipfs-dep": "~0.4.21",
88-
"interface-ipfs-core": "~0.105.0",
88+
"interface-ipfs-core": "~0.106.0",
8989
"ipfsd-ctl": "~0.43.0",
9090
"nock": "^10.0.2",
9191
"stream-equal": "^1.1.1"

src/repo/gc.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const streamToValueWithTransformer = require('../utils/stream-to-value-with-transformer')
5+
const CID = require('cids')
6+
7+
const transform = function (res, callback) {
8+
callback(null, res.map(r => ({
9+
err: r.Err ? new Error(r.Err) : null,
10+
cid: (r.Key || {})['/'] ? new CID(r.Key['/']) : null
11+
})))
12+
}
413

514
module.exports = (send) => {
615
return promisify((opts, callback) => {
716
if (typeof (opts) === 'function') {
817
callback = opts
918
opts = {}
1019
}
11-
send({
20+
21+
const request = {
1222
path: 'repo/gc',
1323
qs: opts
14-
}, callback)
24+
}
25+
send(request, (err, result) => {
26+
if (err) {
27+
return callback(err)
28+
}
29+
30+
streamToValueWithTransformer(result, transform, callback)
31+
})
1532
})
1633
}

0 commit comments

Comments
 (0)