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

Commit 7ba0343

Browse files
magik6kdaviddias
authored andcommitted
feat(dag): proper get implementation
1 parent 9bf1c6c commit 7ba0343

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/dag/dag.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const dagCBOR = require('ipld-dag-cbor')
55
const promisify = require('promisify-es6')
66
const CID = require('cids')
77
const multihash = require('multihashes')
8+
const block = require('./block')
89

910
function noop () {}
1011

@@ -96,14 +97,28 @@ module.exports = (send) => {
9697
}
9798

9899
send({
99-
path: 'dag/get',
100+
path: 'dag/resolve',
100101
args: cid + '/' + path,
101102
qs: options
102-
}, (err, result) => {
103+
}, (err, resolved) => {
103104
if (err) {
104105
return callback(err)
105106
}
106-
callback(undefined, {value: result})
107+
108+
let resolvedCid = new CID(resolved['Cid']['/'])
109+
110+
block(send).get(resolvedCid, (err, blk) => {
111+
if (err) {
112+
return callback(err)
113+
}
114+
115+
if (resolvedCid.codec === 'dag-cbor') {
116+
dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback)
117+
}
118+
if (resolvedCid.codec === 'dag-pb') {
119+
dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback)
120+
}
121+
})
107122
})
108123
})
109124
}

0 commit comments

Comments
 (0)