From 203bf99e297275425b36553bdb007bb1415c6e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 4 May 2017 22:16:39 +0200 Subject: [PATCH 1/2] Implement dag.get --- src/api/dag.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/api/dag.js b/src/api/dag.js index ab81f041c..59febe5e0 100644 --- a/src/api/dag.js +++ b/src/api/dag.js @@ -71,7 +71,40 @@ module.exports = (send) => { } }), 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 (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}) + }) }) } From e44790330fbdc51330474effd3c30ea3d4da7d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Tenorio=20Forn=C3=A9s?= Date: Tue, 20 Jun 2017 13:11:33 +0200 Subject: [PATCH 2/2] Handle dag put response, enable CIDs for dag get and fix dag get request param --- package.json | 1 + src/api/dag.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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 59febe5e0..6e86f62e8 100644 --- a/src/api/dag.js +++ b/src/api/dag.js @@ -66,7 +66,11 @@ 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) + } }) } }), @@ -83,6 +87,10 @@ module.exports = (send) => { options = options || {} + if (CID.isCID(cid)) { + cid = cid.toBaseEncodedString() + } + if (typeof cid === 'string') { const split = cid.split('/') cid = split[0] @@ -97,7 +105,7 @@ module.exports = (send) => { send({ path: 'dag/get', - args: cid + path, + args: cid + '/' + path, qs: options }, (err, result) => { if (err) {