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

Commit eb95d0a

Browse files
Antonio Tenorio-Fornésdaviddias
Antonio Tenorio-Fornés
authored andcommitted
Feat/dag api (#568)
* Implement dag.get * Handle dag put response, enable CIDs for dag get and fix dag get request param
1 parent 5e1fde7 commit eb95d0a

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"glob-escape": "0.0.2",
3333
"ipfs-block": "~0.5.5",
3434
"ipfs-unixfs": "~0.1.10",
35+
"ipld-dag-cbor": "^0.11.1",
3536
"ipld-dag-pb": "~0.9.5",
3637
"is-ipfs": "~0.3.0",
3738
"isstream": "^0.1.2",

src/api/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)