From 2e4156472c2d530b4c9511711b6469a7879408b6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 21 Jun 2018 23:07:24 +0100 Subject: [PATCH 1/4] fix: allow put empty block & add X-Stream-Output header on get This PR allows the test in https://github.com/ipfs/interface-ipfs-core/pull/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 https://github.com/ipfs/js-ipfs-api/pull/789 tested by https://github.com/ipfs/interface-ipfs-core/pull/308 License: MIT Signed-off-by: Alan Shaw --- src/http/api/resources/block.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/http/api/resources/block.js b/src/http/api/resources/block.js index f536fb2a22..1bae34fd8d 100644 --- a/src/http/api/resources/block.js +++ b/src/http/api/resources/block.js @@ -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 @@ -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([ From 2e382435931d7b814a2f9980ccc6f446ac161672 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 22 Jun 2018 09:08:16 +0100 Subject: [PATCH 2/4] chore: update interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 413db75db0..61ec67db95 100644 --- a/package.json +++ b/package.json @@ -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", From 41d3b50bb4512dc168fa6d76911ea10ea9f82175 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 25 Jun 2018 11:54:44 +0100 Subject: [PATCH 3/4] chore: update ipfs-api dependency License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61ec67db95..e3383397de 100644 --- a/package.json +++ b/package.json @@ -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", From c7e83564d33119513c1686554f38e18e9c864a39 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 26 Jun 2018 20:32:01 +0100 Subject: [PATCH 4/4] chore: fix the hack, open the repo not the datastore License: MIT Signed-off-by: Alan Shaw --- src/core/components/pin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/components/pin.js b/src/core/components/pin.js index 93f79a8e74..b9a60b7f75 100644 --- a/src/core/components/pin.js +++ b/src/core/components/pin.js @@ -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)