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

Commit

Permalink
fix: use trickle builder in daemon mode too (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored and alanshaw committed May 22, 2019
1 parent 5905760 commit 62b873f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/http/api/resources/files-regular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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()
Expand Down
34 changes: 34 additions & 0 deletions test/http-api/inject/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 62b873f

Please sign in to comment.