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

Commit

Permalink
small last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 16, 2016
1 parent e57dff5 commit c58ad06
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
31 changes: 6 additions & 25 deletions src/http-api/resources/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,7 @@ exports.put = {
// main route handler which is called after the above `parseArgs`, but only if the args were valid
handler: (request, reply) => {
const node = request.pre.args.node

const data = new Buffer(node.Data)
const links = node.Links.map((link) => ({
name: link.Name,
hash: new Buffer(bs58.decode(link.Hash)),
size: link.Size
}))

const dagNode = new DAGNode(data, links)
const dagNode = new DAGNode(new Buffer(node.Data), node.Links)

request.server.app.ipfs.object.put(dagNode, (err, obj) => {
if (err) {
Expand All @@ -124,15 +116,7 @@ exports.put = {
Code: 0
}).code(500)
}

return reply({
Hash: bs58.encode(dagNode.multihash()).toString(),
Links: dagNode.links.map((link) => ({
Name: link.name,
Hash: bs58.encode(link.hash).toString(),
Size: link.size
}))
})
return reply(dagNode.toJSON())
})
}
}
Expand Down Expand Up @@ -189,7 +173,7 @@ exports.links = {
handler: (request, reply) => {
const key = request.pre.args.key

request.server.app.ipfs.object.links(key, (err, links) => {
request.server.app.ipfs.object.get(key, (err, node) => {
if (err) {
log.error(err)
return reply({
Expand All @@ -198,13 +182,10 @@ exports.links = {
}).code(500)
}

const res = node.toJSON()
return reply({
Hash: bs58.encode(key).toString(),
Links: links.map((link) => ({
Name: link.name,
Hash: bs58.encode(link.hash).toString(),
Size: link.size
}))
Hash: res.Hash,
Links: res.Links
})
})
}
Expand Down
4 changes: 3 additions & 1 deletion test/http-api-tests/test-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ module.exports = (httpAPI) => {
form.append('data', fs.createReadStream(filePath))
const headers = form.getHeaders()
const expectedResult = {
Data: new Buffer('another'),
Hash: 'QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm',
Links: [{
Name: 'some link',
Hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39V',
Size: 8
}]
}],
Size: 68
}

streamToPromise(form).then((payload) => {
Expand Down

0 comments on commit c58ad06

Please sign in to comment.