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

Commit c58ad06

Browse files
small last fixes
1 parent e57dff5 commit c58ad06

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

src/http-api/resources/object.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,7 @@ exports.put = {
106106
// main route handler which is called after the above `parseArgs`, but only if the args were valid
107107
handler: (request, reply) => {
108108
const node = request.pre.args.node
109-
110-
const data = new Buffer(node.Data)
111-
const links = node.Links.map((link) => ({
112-
name: link.Name,
113-
hash: new Buffer(bs58.decode(link.Hash)),
114-
size: link.Size
115-
}))
116-
117-
const dagNode = new DAGNode(data, links)
109+
const dagNode = new DAGNode(new Buffer(node.Data), node.Links)
118110

119111
request.server.app.ipfs.object.put(dagNode, (err, obj) => {
120112
if (err) {
@@ -124,15 +116,7 @@ exports.put = {
124116
Code: 0
125117
}).code(500)
126118
}
127-
128-
return reply({
129-
Hash: bs58.encode(dagNode.multihash()).toString(),
130-
Links: dagNode.links.map((link) => ({
131-
Name: link.name,
132-
Hash: bs58.encode(link.hash).toString(),
133-
Size: link.size
134-
}))
135-
})
119+
return reply(dagNode.toJSON())
136120
})
137121
}
138122
}
@@ -189,7 +173,7 @@ exports.links = {
189173
handler: (request, reply) => {
190174
const key = request.pre.args.key
191175

192-
request.server.app.ipfs.object.links(key, (err, links) => {
176+
request.server.app.ipfs.object.get(key, (err, node) => {
193177
if (err) {
194178
log.error(err)
195179
return reply({
@@ -198,13 +182,10 @@ exports.links = {
198182
}).code(500)
199183
}
200184

185+
const res = node.toJSON()
201186
return reply({
202-
Hash: bs58.encode(key).toString(),
203-
Links: links.map((link) => ({
204-
Name: link.name,
205-
Hash: bs58.encode(link.hash).toString(),
206-
Size: link.size
207-
}))
187+
Hash: res.Hash,
188+
Links: res.Links
208189
})
209190
})
210191
}

test/http-api-tests/test-object.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ module.exports = (httpAPI) => {
112112
form.append('data', fs.createReadStream(filePath))
113113
const headers = form.getHeaders()
114114
const expectedResult = {
115+
Data: new Buffer('another'),
115116
Hash: 'QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm',
116117
Links: [{
117118
Name: 'some link',
118119
Hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V',
119120
Size: 8
120-
}]
121+
}],
122+
Size: 68
121123
}
122124

123125
streamToPromise(form).then((payload) => {

0 commit comments

Comments
 (0)