Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Feat(dag): DAG api (#568)
Browse files Browse the repository at this point in the history
* Implement dag.get

* Handle dag put response, enable CIDs for dag get and fix dag get request param
  • Loading branch information
atfornes authored and daviddias committed Apr 5, 2018
1 parent 9463d3a commit 93a9af9
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/dag/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
})
})
}

Expand Down

0 comments on commit 93a9af9

Please sign in to comment.