-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Conversation
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.
@@ -4,7 +4,7 @@ const gulp = require('gulp') | |||
const parallel = require('async/parallel') | |||
const series = require('async/series') | |||
const createTempRepo = require('./test/utils/create-repo-nodejs.js') | |||
const HTTPAPI = require('./src/http-api') | |||
const HTTPAPI = require('./src/http') |
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.
It makes sense to call this http
module now daemon
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 Yeah it does, but in go-ipfs
it's http
, so should we stick to the reference implementation ? I don't mind the rename though
go-ipfs
Edit: added link.
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.
Let's keep http then :)
src/http/api/resources/files.js
Outdated
// const mime = require('mime-types') | ||
// const GatewayResolver = require('../gateway/resolver') | ||
// const PathUtils = require('../gateway/utils/path') | ||
// const Stream = require('stream') |
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.
If not used please delete.
src/http/api/resources/files.js
Outdated
// } | ||
// }) | ||
// } | ||
// } |
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.
If not used please delete.
test/gateway/index.js
Outdated
// | ||
// fs.readdirSync(path.join(__dirname, '/over-ipfs-api')) | ||
// .forEach((file) => require('./over-ipfs-api/' + file)(ctl)) | ||
// }) |
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.
Why disabling these tests? They should continue active and passing at all times.
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.
These tests are still active in the http-api
tests, but not for the gateway
tests. I thought it might be bad to duplicate them.
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.
If it is not used, don't let it comment out. The Gateway requires different kind of tests.
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.
got it 👍
2fcbeb8
to
dd5a5e6
Compare
dd5a5e6
to
d05591a
Compare
Ok, spoke too soon, got a ton (infinite) errors while downloading a video:
That said, the streaming didn't stop nor the node crashed. |
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.
applying as comments as I can push review of a PR I opened
src/http/gateway/resolver.js
Outdated
}) | ||
}) | ||
|
||
const noop = 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.
Move to top of the file and replace for function noop () {}
src/http/gateway/resolver.js
Outdated
const resolveDirectory = promisify((ipfs, path, multihash, callback) => { | ||
if (!callback) { | ||
callback = noop | ||
} |
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.
Can be replaced by callback = callback || noop
src/http/gateway/resolver.js
Outdated
callback = noop | ||
} | ||
|
||
mh.validate(mh.fromB58String(multihash)) |
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.
This means that it won't work with CID. Needs to be using the https://github.com/ipld/js-cid module
src/http/gateway/resolver.js
Outdated
|
||
ipfs | ||
.object | ||
.get(multihash, { enc: 'base58' }) |
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 prefer to use the DAG API for this ipfs.dag.get
if possible (if it isn't, report as a bug why)
src/http/gateway/resolver.js
Outdated
} | ||
|
||
return callback(null, html.build(path, links)) | ||
}) |
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.
Mixing Promises and Callbacks has been historically a recipe for problems. Here the error is not being caught (promise) and the promise is possibly returning before the callback fires.
Let's continue using Callbacks everywhere when possible.
src/http/gateway/routes/gateway.js
Outdated
|
||
gateway.route({ | ||
method: '*', | ||
path: '/ipfs/{hash*}', |
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.
It will be a snap to add /ipld
in the future :)
src/http/gateway/utils/html.js
Outdated
</body> | ||
</html> | ||
` | ||
} |
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.
Ok, so this is the file that generates the Dir preview 👍
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.
Will considering renaming it to /dir-view/index.js
and then /dir-view/style.js
require('./routes')(this.server) | ||
require('./api/routes')(this.server) | ||
// load gateway routes | ||
require('./gateway/routes')(this.server) |
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.
🎉
test/gateway/index.js
Outdated
const path = require('path') | ||
const clean = require('../utils/clean') | ||
|
||
describe('HTTP GATEWAY', () => { |
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.
GATEWAY can be Gateway
as it is not an acronym
test/gateway/index.js
Outdated
clean(repoTests) | ||
done() | ||
}) | ||
}) |
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.
Does the gateway need the go-ipfs test repo? It would be better to see it working with the default js-ipfs repo.
Pushed my review. Mostly it is structure/cosmetic changes. We do need a test that streams a large file to ensure that is working properly. Also, currently the tests are all happening in Node.js land. It would be ideal to run them in the browser so that browser things get checked. One more thing: Currently CORS is being set by default to *, this will have to change. |
src/http/gateway/resolver.js
Outdated
log('leaf node: ', currentMultihash) | ||
|
||
// TODO: Check if it is a directory by using Unixfs Type, right now | ||
// it won't detect empty dirs |
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.
Should be checking to see if it's https://github.com/ipfs/js-ipfs-unixfs/blob/master/src/unixfs.proto.js#L6
Otherwise, it will fail for empty dirs or misbehave for shards.
* feat: add gateway route to daemon * feat: adding Gateway endeavour - improve codebase * clean up, remove commented out lines. (#971) * clean up, remove commented out lines. * cleaning code, removing commented out blocks. * gateway initial tests. * clean up , working tests on node v8.4.0 License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * fix using js-ipfs-repo in gateway tests. License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * Using unix-fs to detect dirs, replacing object.get with DAG.get, CID checks License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * rename checkHash -> checkCID License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * gateway tests: init a fresh repo
Travis is really unhappy here. |
2349f1e
to
9dc8c99
Compare
* feat: add gateway route to daemon * feat: adding Gateway endeavour - improve codebase * clean up, remove commented out lines. (#971) * clean up, remove commented out lines. * cleaning code, removing commented out blocks. * gateway initial tests. * clean up , working tests on node v8.4.0 License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * fix using js-ipfs-repo in gateway tests. License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * Using unix-fs to detect dirs, replacing object.get with DAG.get, CID checks License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * rename checkHash -> checkCID License: MIT Signed-off-by: Yahya <ya7yaz@gmail.com> * gateway tests: init a fresh repo
test/gateway/index.js
Outdated
done() | ||
}) | ||
}) | ||
}) |
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 believe that is missing to merge this PR is more tests.
There should be tests for:
- Fetching a file with a mime-type that is not text (i.e a pdf or an image)
- Loading a webpage (one for each type of index.html)
- Loading a webpage from a pagh (QmHASH/a/b/c -> loads the webpage in that path)
And other tests for future PR (I don't want to block this any longer)
- CORS tests (make sure config is respected)
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.
@ya7ya what do you think?
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 I'm working on tests now, It took me a minute to figure out aegir :D and interface-ipfs-core. and i'm trying to follow that to complete the tests for the gateway.
I'll add the tests you mentioned above and check the Error with libp2p.dial you mentioned aswell. I'll try to get this done As soon as possible 👍
Just saw this error running the tests locally:
Weirdly it is not crashing the tests and so it doesn't get detected by CI. |
}) | ||
|
||
it('stream a large file', (done) => { | ||
let bigFileHash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' |
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.
@ya7ya where does this hash/file come from? Doesn't seem it got added anywhere
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.
Trying to load it through the gateway ipfs.io, I get:
https://ipfs.io/ipfs/Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq
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 thats from the 15mb random file in the fixtures in interface-ipfs-core
, I just noticed I forgot to add it to files.add
in the before section. So sorry about this.
Ok, got it to pass all tests locally. Amazing work and effort @ya7ya and @harshjv, thank you so much for taking this on and not letting it go until it was completed 💯 @dignifiedquire @victorbjelkholm @dryajov would you like to do a review before the merge? This is a big PR that has gone through many iterations, having an extra pair of eyeballs reviewing it would be good :) |
test/gateway/index.js
Outdated
http.api = new API(undefined, { | ||
const repoPath = os.tmpdir() + '/ipfs-' + Math.random().toString().substring(2, 8) + '-' + Date.now() | ||
|
||
http.api = new API(repoPath, { |
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.
Thought this would fix it. Seems it is not the issue.
src/http/gateway/dir-view/index.js
Outdated
const pathUtil = require('../utils/path') | ||
|
||
function getParentDirectoryURL (originalParts) { | ||
const parts = originalParts.splice() |
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.
why splice? for getting an array copy we use .slice usually
@ya7ya @harshjv