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

fix: allow put empty block & add X-Stream-Output header on get #1408

Merged
merged 4 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"expose-loader": "~0.7.5",
"form-data": "^2.3.2",
"hat": "0.0.3",
"interface-ipfs-core": "~0.68.2",
"interface-ipfs-core": "~0.69.0",
"ipfsd-ctl": "~0.37.3",
"lodash": "^4.17.10",
"mocha": "^5.1.1",
Expand Down Expand Up @@ -107,7 +107,7 @@
"hoek": "^5.0.3",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "^0.4.1",
"ipfs-api": "^22.0.0",
"ipfs-api": "^22.1.1",
"ipfs-bitswap": "~0.20.0",
"ipfs-block": "~0.7.1",
"ipfs-block-service": "~0.14.0",
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = function pin (self) {
}),

// hack for CLI tests
cb => repo.closed ? repo.datastore.open(cb) : cb(null, null),
cb => repo.closed ? repo.open(cb) : cb(null, null),

// save root to datastore under a consistent key
cb => repo.datastore.put(pinDataStoreKey, root.multihash, cb)
Expand Down
21 changes: 15 additions & 6 deletions src/http/api/resources/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ exports.get = {
}

if (block) {
return reply(block.data)
return reply(block.data).header('X-Stream-Output', '1')
}

return reply({
Message: 'Block was unwanted before it could be remotely retrieved',
Code: 0
Expand All @@ -63,32 +64,40 @@ exports.put = {
// pre request handler that parses the args and returns `data` which is assigned to `request.pre.args`
parseArgs: (request, reply) => {
if (!request.payload) {
return reply("File argument 'data' is required").code(400).takeover()
return reply({
Message: "File argument 'data' is required",
Code: 0
}).code(400).takeover()
}

const parser = multipart.reqParser(request.payload)
var file

parser.on('file', (fileName, fileStream) => {
file = Buffer.alloc(0)

fileStream.on('data', (data) => {
file = data
file = Buffer.concat([file, data])
})
})

parser.on('end', () => {
if (!file) {
return reply("File argument 'data' is required").code(400).takeover()
return reply({
Message: "File argument 'data' is required",
Code: 0
}).code(400).takeover()
}

return reply({
data: file.toString()
data: file
})
})
},

// main route handler which is called after the above `parseArgs`, but only if the args were valid
handler: (request, reply) => {
const data = Buffer.from(request.pre.args.data)
const data = request.pre.args.data
const ipfs = request.server.app.ipfs

waterfall([
Expand Down