Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
send the options for file and pin operations that hit 'send-files-str…
Browse files Browse the repository at this point in the history
…eam' under the 'qs' key. Allows any options passed to ipfs.file|pin.add-ish to be turned into qs params instead of adding all of them individually
  • Loading branch information
JonKrone committed Mar 2, 2018
1 parent f4312ac commit 2424a5a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/files/add-pull-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
const SendFilesStream = require('../utils/send-files-stream')
const toPull = require('stream-to-pull-stream')

module.exports = (send) => (options) => toPull(SendFilesStream(send, 'add')(options))
module.exports = (send) => (options) =>
toPull(SendFilesStream(send, 'add')({ qs: options }))
2 changes: 1 addition & 1 deletion src/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = (send) => {

const files = [].concat(_files)

const stream = createAddStream(options)
const stream = createAddStream({ qs: options })
const concat = ConcatStream((result) => callback(null, result))
stream.once('error', callback)
stream.pipe(concat)
Expand Down
2 changes: 1 addition & 1 deletion src/files/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = (send) => {
qs: opts
}

const stream = sendFilesStream(options)
const stream = sendFilesStream({ qs: options })
const concat = concatStream((result) => callback(null, result))
stream.once('error', callback)
stream.pipe(concat)
Expand Down
36 changes: 36 additions & 0 deletions test/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,42 @@ describe('.files (the MFS API part)', function () {
})
})

it('files.add pins by default', (done) => {
const newContent = Buffer.from(String(Math.random()))

ipfs.pin.ls((err, pins) => {
expect(err).to.not.exist()
const initialPinCount = pins.length
ipfs.files.add(newContent, (err, res) => {
expect(err).to.not.exist()

ipfs.pin.ls((err, pins) => {
expect(err).to.not.exist()
expect(pins.length).to.eql(initialPinCount + 1)
done()
})
})
})
})

it('files.add with pin=false', (done) => {
const newContent = Buffer.from(String(Math.random()))

ipfs.pin.ls((err, pins) => {
expect(err).to.not.exist()
const initialPinCount = pins.length
ipfs.files.add(newContent, { pin: false }, (err, res) => {
expect(err).to.not.exist()

ipfs.pin.ls((err, pins) => {
expect(err).to.not.exist()
expect(pins.length).to.eql(initialPinCount)
done()
})
})
})
})

HASH_ALGS.forEach((name) => {
it(`files.add with hash=${name} and raw-leaves=false`, (done) => {
const content = String(Math.random() + Date.now())
Expand Down
10 changes: 7 additions & 3 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('.util', () => {
const filepath = path.join(os.tmpdir(), `${content}.txt`)
fs.writeFileSync(filepath, content)

return ipfs.util.addFromFs(filepath, { 'only-hash': true })
return ipfs.util.addFromFs(filepath, { onlyHash: true })
.then(out => {
fs.unlinkSync(filepath)
return expectTimeout(ipfs.object.get(out[0].hash), 4000)
Expand All @@ -120,15 +120,19 @@ describe('.util', () => {
})
})

it('https', (done) => {
it('https', function (done) {
this.timeout(20 * 1000)

ipfs.util.addFromURL('https://example.com/', (err, result) => {
expect(err).to.not.exist()
expect(result.length).to.equal(1)
done()
})
})

it('http with redirection', (done) => {
it('http with redirection', function (done) {
this.timeout(20 * 1000)

ipfs.util.addFromURL('http://covers.openlibrary.org/book/id/969165.jpg', (err, result) => {
expect(err).to.not.exist()
expect(result[0].hash).to.equal('QmaL9zy7YUfvWmtD5ZXp42buP7P4xmZJWFkm78p8FJqgjg')
Expand Down

0 comments on commit 2424a5a

Please sign in to comment.