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', () => {