-
Notifications
You must be signed in to change notification settings - Fork 299
feat: Add urls directly. #121
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
|
@@ -63,6 +64,10 @@ function IpfsAPI (host_or_multiaddr, port) { | |
opts = {} | ||
} | ||
|
||
if (typeof files === 'string' && files.startsWith('http')) { | ||
files = request(files) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sync call will block the loop (or am I missing some ES6 thing?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The request is a stream object, so it will not block but will be piped into the new request effectively as far as I understand :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. `23:09 <+daviddias> dignifiedquire: interesting, so our thing understands 'strings', 'paths', 'buffers' and 'streams' too?`` Sweet! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better add a test and docs for adding with a stream though, otherwise that might change in the future and then we don't realize what broke the add by url was actually the lack of add by stream |
||
} | ||
|
||
return requestAPI('add', null, opts, files, cb) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,19 @@ describe('IPFS Node.js API wrapper tests', function () { | |
} | ||
}) | ||
}) | ||
it('adds a url', function (done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for adding a test :D |
||
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 () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if request works in the browser. But the tests are testing that this actually works no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not being able to confirm, but read somewhere that request gets polifilled in browserify. Nevertheless, there is https://www.npmjs.com/package/browser-request for that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diasdavid @victorbjelkholm no need for all that, all tests are passing in the browser, request is 100% browser compatible :)