From 62b873f7b81364bd674c20c232a7a85c11401888 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 22 May 2019 09:17:08 +0100 Subject: [PATCH] fix: use trickle builder in daemon mode too (#2085) --- src/http/api/resources/files-regular.js | 6 +++-- test/http-api/inject/files.js | 34 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/http/api/resources/files-regular.js b/src/http/api/resources/files-regular.js index 7175b17972..ddfa03932d 100644 --- a/src/http/api/resources/files-regular.js +++ b/src/http/api/resources/files-regular.js @@ -161,7 +161,8 @@ exports.add = { 'only-hash': Joi.boolean(), pin: Joi.boolean().default(true), 'wrap-with-directory': Joi.boolean(), - chunker: Joi.string() + chunker: Joi.string(), + trickle: Joi.boolean() }) // TODO: Necessary until validate "recursive", "stream-channels" etc. .options({ allowUnknown: true }) @@ -218,7 +219,8 @@ exports.add = { hashAlg: request.query.hash, wrapWithDirectory: request.query['wrap-with-directory'], pin: request.query.pin, - chunker: request.query.chunker + chunker: request.query.chunker, + strategy: request.query.trickle ? 'trickle' : 'balanced' } const aborter = abortable() diff --git a/test/http-api/inject/files.js b/test/http-api/inject/files.js index f36582e828..7c1c0b6a48 100644 --- a/test/http-api/inject/files.js +++ b/test/http-api/inject/files.js @@ -76,6 +76,40 @@ module.exports = (http) => { expect(res.statusCode).to.equal(200) expect(multibase.isEncoded(JSON.parse(res.result).Hash)).to.deep.equal('base64') }) + + it('should add data using the trickle importer', async () => { + const form = new FormData() + form.append('data', Buffer.from('TEST\n')) + const headers = form.getHeaders() + + const payload = await streamToPromise(form) + const res = await api.inject({ + method: 'POST', + url: '/api/v0/add?trickle=true&pin=false', + headers, + payload + }) + + expect(res.statusCode).to.equal(200) + expect(JSON.parse(res.result).Hash).to.equal('QmRJTAvvv1UNgCXxK9grf6u2pCT2ZQ2wCwsojpC1sTjkp9') + }) + + it('should add data using the balanced importer', async () => { + const form = new FormData() + form.append('data', Buffer.from('TEST\n')) + const headers = form.getHeaders() + + const payload = await streamToPromise(form) + const res = await api.inject({ + method: 'POST', + url: '/api/v0/add?pin=false', + headers, + payload + }) + + expect(res.statusCode).to.equal(200) + expect(JSON.parse(res.result).Hash).to.equal('Qmdudp5XvJr7KrqK6fQ7m2ACStoRxuwfovNHnY6dAAeUis') + }) }) describe('/cat', () => {