This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 296
Files add interface #288
Merged
Merged
Files add interface #288
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d45b09
Make ipfs.files.add return DAGNodes.
hackergrrl 1348b45
Add "addUrl" API.
hackergrrl c6d77be
Add "addFiles" API.
hackergrrl 716daca
Update 'files' and 'util' command paths.
hackergrrl dfdb998
Move "add" tests to interface-ipfs-core.
hackergrrl ee6cfd3
Make ipfs.files.add return wrapped path+node.
hackergrrl 6207ad4
fix linting, test with complete interface-core tests
daviddias b61b3cd
add latest interface-ipfs-core
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
|
||
const async = require('async') | ||
const getDagNode = require('./get-dagnode') | ||
|
||
// transform { Hash: '...' } objects into { path: 'string', node: DAGNode } | ||
module.exports = function (err, res, send, done) { | ||
if (err) { | ||
return done(err) | ||
} | ||
async.map(res, function map (entry, next) { | ||
getDagNode(send, entry.Hash, function (err, node) { | ||
if (err) { | ||
return next(err) | ||
} | ||
var obj = { | ||
path: entry.Name, | ||
node: node | ||
} | ||
next(null, obj) | ||
}) | ||
}, function (err, res) { | ||
done(err, res) | ||
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 could have been just passed done directly |
||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const addToDagNodesTransform = require('../add-to-dagnode-transform') | ||
|
||
module.exports = (send) => { | ||
return function add (path, opts, cb) { | ||
if (typeof (opts) === 'function' && cb === undefined) { | ||
cb = opts | ||
opts = {} | ||
} | ||
|
||
if (typeof (path) !== 'string') { | ||
return cb(new Error('"path" must be a string')) | ||
} | ||
|
||
var sendWithTransform = send.withTransform(addToDagNodesTransform) | ||
|
||
return sendWithTransform('add', null, opts, path, cb) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
|
||
const Wreck = require('wreck') | ||
const addToDagNodesTransform = require('../add-to-dagnode-transform') | ||
|
||
module.exports = (send) => { | ||
return function add (url, opts, cb) { | ||
if (typeof (opts) === 'function' && cb === undefined) { | ||
cb = opts | ||
opts = {} | ||
} | ||
|
||
if (typeof url !== 'string' || !url.startsWith('http')) { | ||
return cb(new Error('"url" param must be an http(s) url')) | ||
} | ||
|
||
var sendWithTransform = send.withTransform(addToDagNodesTransform) | ||
|
||
Wreck.request('GET', url, null, (err, res) => { | ||
if (err) return cb(err) | ||
|
||
sendWithTransform('add', null, opts, res, cb) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
const DAGNode = require('ipfs-merkle-dag').DAGNode | ||
const bl = require('bl') | ||
const async = require('async') | ||
|
||
module.exports = function (send, hash, cb) { | ||
// Retrieve the object and its data in parallel, then produce a DAGNode | ||
// instance using this information. | ||
async.parallel([ | ||
function get (done) { | ||
send('object/get', hash, null, null, done) | ||
}, | ||
|
||
function data (done) { | ||
// WORKAROUND: request the object's data separately, since raw bits in JSON | ||
// are interpreted as UTF-8 and corrupt the data. | ||
// See https://github.com/ipfs/go-ipfs/issues/1582 for more details. | ||
send('object/data', hash, null, null, done) | ||
}], | ||
|
||
function done (err, res) { | ||
if (err) { | ||
return cb(err) | ||
} | ||
|
||
var object = res[0] | ||
var stream = res[1] | ||
|
||
stream.pipe(bl(function (err, data) { | ||
if (err) { | ||
return cb(err) | ||
} | ||
|
||
cb(err, new DAGNode(data, object.Links)) | ||
})) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please try to avoid adding async
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.
roger. Due to time constraints, can we make that a issue to hit later? It would be good to explain in one paragraph (or even one line -> "async is a huge dependency, makes our browser lib fat") so that @noffle and other contribs try to avoid it in the future?
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.
sure there is already an issue on js-ipfs for exactly that