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

Commit 93a9af9

Browse files
Antonio Tenorio-Fornésdaviddias
Antonio Tenorio-Fornés
authored andcommitted
Feat(dag): DAG api (#568)
* Implement dag.get * Handle dag put response, enable CIDs for dag get and fix dag get request param
1 parent 9463d3a commit 93a9af9

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

src/dag/dag.js

+43-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,53 @@ module.exports = (send) => {
6666
if (err) {
6767
return callback(err)
6868
}
69-
// TODO handle the result
69+
if (result.Cid) {
70+
return callback(null, new CID(result.Cid['/']))
71+
} else {
72+
return callback(result)
73+
}
7074
})
7175
}
7276
}),
7377
get: promisify((cid, path, options, callback) => {
74-
// TODO
78+
if (typeof path === 'function') {
79+
callback = path
80+
path = undefined
81+
}
82+
83+
if (typeof options === 'function') {
84+
callback = options
85+
options = {}
86+
}
87+
88+
options = options || {}
89+
90+
if (CID.isCID(cid)) {
91+
cid = cid.toBaseEncodedString()
92+
}
93+
94+
if (typeof cid === 'string') {
95+
const split = cid.split('/')
96+
cid = split[0]
97+
split.shift()
98+
99+
if (split.length > 0) {
100+
path = split.join('/')
101+
} else {
102+
path = '/'
103+
}
104+
}
105+
106+
send({
107+
path: 'dag/get',
108+
args: cid + '/' + path,
109+
qs: options
110+
}, (err, result) => {
111+
if (err) {
112+
return callback(err)
113+
}
114+
callback(undefined, {value: result})
115+
})
75116
})
76117
}
77118

0 commit comments

Comments
 (0)