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

Commit 52f7aa7

Browse files
authored
fix: allow put empty block & add X-Stream-Output header on get (#1408)
* fix: allow put empty block & add X-Stream-Output header on get This PR allows the test in ipfs-inactive/interface-js-ipfs-core#308 to pass. X-Stream-Output header is added to block.get reply for parity with go-ipfs. block.put is altered to allow an empty block to be put (again for fetaure parity with go-ipfs) but only if there is a multipart file part for it. Error responses have also been improved. refs ipfs-inactive/js-ipfs-http-client#789 tested by ipfs-inactive/interface-js-ipfs-core#308 License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: update interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: update ipfs-api dependency License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io> * chore: fix the hack, open the repo not the datastore License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
1 parent 2e94184 commit 52f7aa7

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"expose-loader": "~0.7.5",
7474
"form-data": "^2.3.2",
7575
"hat": "0.0.3",
76-
"interface-ipfs-core": "~0.68.2",
76+
"interface-ipfs-core": "~0.69.0",
7777
"ipfsd-ctl": "~0.37.3",
7878
"lodash": "^4.17.10",
7979
"mocha": "^5.1.1",
@@ -107,7 +107,7 @@
107107
"hoek": "^5.0.3",
108108
"human-to-milliseconds": "^1.0.0",
109109
"interface-datastore": "^0.4.1",
110-
"ipfs-api": "^22.0.0",
110+
"ipfs-api": "^22.1.1",
111111
"ipfs-bitswap": "~0.20.0",
112112
"ipfs-block": "~0.7.1",
113113
"ipfs-block-service": "~0.14.0",

src/core/components/pin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = function pin (self) {
9292
}),
9393

9494
// hack for CLI tests
95-
cb => repo.closed ? repo.datastore.open(cb) : cb(null, null),
95+
cb => repo.closed ? repo.open(cb) : cb(null, null),
9696

9797
// save root to datastore under a consistent key
9898
cb => repo.datastore.put(pinDataStoreKey, root.multihash, cb)

src/http/api/resources/block.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ exports.get = {
4949
}
5050

5151
if (block) {
52-
return reply(block.data)
52+
return reply(block.data).header('X-Stream-Output', '1')
5353
}
54+
5455
return reply({
5556
Message: 'Block was unwanted before it could be remotely retrieved',
5657
Code: 0
@@ -63,32 +64,40 @@ exports.put = {
6364
// pre request handler that parses the args and returns `data` which is assigned to `request.pre.args`
6465
parseArgs: (request, reply) => {
6566
if (!request.payload) {
66-
return reply("File argument 'data' is required").code(400).takeover()
67+
return reply({
68+
Message: "File argument 'data' is required",
69+
Code: 0
70+
}).code(400).takeover()
6771
}
6872

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

7276
parser.on('file', (fileName, fileStream) => {
77+
file = Buffer.alloc(0)
78+
7379
fileStream.on('data', (data) => {
74-
file = data
80+
file = Buffer.concat([file, data])
7581
})
7682
})
7783

7884
parser.on('end', () => {
7985
if (!file) {
80-
return reply("File argument 'data' is required").code(400).takeover()
86+
return reply({
87+
Message: "File argument 'data' is required",
88+
Code: 0
89+
}).code(400).takeover()
8190
}
8291

8392
return reply({
84-
data: file.toString()
93+
data: file
8594
})
8695
})
8796
},
8897

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

94103
waterfall([

0 commit comments

Comments
 (0)