Skip to content

Commit

Permalink
feat: Add urls directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 16, 2015
1 parent 375c80a commit 9cdb0a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var multiaddr = require('multiaddr')
var getConfig = require('./config')
var getRequestAPI = require('./request-api')
var request = require('request')

exports = module.exports = IpfsAPI

Expand Down Expand Up @@ -63,6 +64,10 @@ function IpfsAPI (host_or_multiaddr, port) {
opts = {}
}

if (typeof files === 'string' && files.startsWith('http')) {
files = request(files)
}

return requestAPI('add', null, opts, files, cb)
}

Expand Down
13 changes: 13 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ describe('IPFS Node.js API wrapper tests', function () {
}
})
})
it('adds a url', function (done) {
this.timeout(10000)

var url = 'https://raw.githubusercontent.com/ipfs/js-ipfs-api/2a9cc63d7427353f2145af6b1a768a69e67c0588/README.md'
apiClients['a'].add(url, function (err, res) {
if (err) throw err

var added = res[0]

assert.equal(added.Hash, 'QmZmHgEX9baxUn3qMjsEXQzG6DyNcrVnwieQQTrpDdrFvt')
done()
})
})
})

describe('.cat', function () {
Expand Down

0 comments on commit 9cdb0a2

Please sign in to comment.