Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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