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] 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}) + }) }) }