diff --git a/package.json b/package.json index 0c2625c1e..8037a290e 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "glob-escape": "0.0.2", "ipfs-block": "~0.5.5", "ipfs-unixfs": "~0.1.10", + "ipld-dag-cbor": "^0.11.1", "ipld-dag-pb": "~0.9.5", "is-ipfs": "~0.3.0", "isstream": "^0.1.2", diff --git a/src/api/dag.js b/src/api/dag.js index ab81f041c..6e86f62e8 100644 --- a/src/api/dag.js +++ b/src/api/dag.js @@ -66,12 +66,53 @@ module.exports = (send) => { if (err) { return callback(err) } - // TODO handle the result + if (result.Cid) { + return callback(null, new CID(result.Cid['/'])) + } else { + return callback(result) + } }) } }), get: promisify((cid, path, options, callback) => { - // TODO + if (typeof path === 'function') { + callback = path + path = undefined + } + + if (typeof options === 'function') { + callback = options + options = {} + } + + options = options || {} + + if (CID.isCID(cid)) { + cid = cid.toBaseEncodedString() + } + + if (typeof cid === 'string') { + const split = cid.split('/') + cid = split[0] + split.shift() + + if (split.length > 0) { + path = split.join('/') + } else { + path = '/' + } + } + + send({ + path: 'dag/get', + args: cid + '/' + path, + qs: options + }, (err, result) => { + if (err) { + return callback(err) + } + callback(undefined, {value: result}) + }) }) }