Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Adds "files add" http route. #235

Closed
wants to merge 2 commits into from

Conversation

hackergrrl
Copy link
Contributor

Tested to be compatible with a go-ipfs client requesting against the js-ipfs http api.

@daviddias
Copy link
Member

This is pretty rad! Thank you @noffle

})

fileAdder.on('end', () => {
if (written === 0 && file) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the file flag used to signal that at least one file was added?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah file is a boolean that is just used by L77 to generate a no data response from the server. There might be better ways of generating that response if no data is passed to the server in an add call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a 'no data' response? Like, being silent?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the file flag is true, but the written var hasn't been incremented, then a 500 server error is returned because the core failed even though the request had valid data parsed.

If at the end of parsing the request, if file is still false then the request was bad, so 400 Bad Request is returned

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so maybe 'failedToImport' flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid: sorry, can you clarify what you're asking to be named to failedToImport here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe file could be called didParse to flag that the parser emitted a file event, written makes sense to me for the data event from the importer when data has been stored, or maybe imported is better since it is currently storing the number of files imported

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a stab at making this a bit clearer. Lemme know what y'all think!

@hackergrrl
Copy link
Contributor Author

Getting test timeouts -- don't mind the reverts (WIP)..

@daviddias
Copy link
Member

LGTM :) @noffle let me know if you have something to add (based on your last comment) or if I can merge it

@@ -12,7 +12,7 @@ const createTempNode = require('../utils/temp-node')
const repoPath = require('./index').repoPath

describe('bitswap', function () {
this.timeout(20000)
this.timeout(80000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this an env variable? Seems weird to keep defining it everywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are often different depending on the test, that's why they are set specifically in here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this unrelated change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could break this into another PR, but timeouts were making my local tests fail. :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make it at least a separate commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they already are -- see 5d55b3c. Did I miss one?

@RichardLitt
Copy link
Member

Might be good to add some failing tests, too - all of the ones here are positive.

fileAdder.on('data', (file) => {
serialize.write({
Name: file.path,
Hash: bs58.encode(file.multihash).toString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use mh.toB58String(file.multihash) from the multihashes package insteada

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do!

@hackergrrl
Copy link
Contributor Author

Assuming tests pass, should be good to go!

@hackergrrl
Copy link
Contributor Author

@diasdavid teamcity's failure is a cached one it looks like; it's just whining about a timeout. If you're okay with how this PR looks, then please feel free to merge!

@daviddias
Copy link
Member

@noffle looks good :) can we just get the commits squashed please?

@nginnever
Copy link
Member

woo add command!

squashed commits and LGTM, gj @noffle

@nginnever
Copy link
Member

nginnever commented May 21, 2016

@noffle one thing i forgot about this PR is that it doesn't address the cli looking for the daemon to be on. Also the CLI tests are not there that can now use the http resource for the tests. I have these tests as well

I have written this code before and I just used it on your new add http-api resource and it works all ways!

I can open up a separate PR once this is merged maybe 'add cli updates'

https://gist.github.com/nginnever/39251f1d1572634e9699c875628dd00b

@hackergrrl
Copy link
Contributor Author

@nginnever That's safe to put in another PR, right? It sounds like you have a lot of context for what needs to happen for these changes -- if you could make that happen that'd be super awesome. ❤️

@daviddias
Copy link
Member

Master needs to be rebased onto this branch for the clean merge. @noffle could you do that?

@nginnever as @noffle suggested, please open a issue/PR with that missing part.

@daviddias
Copy link
Member

Only one more thing to go. This PR needs to update https://github.com/ipfs/js-ipfs/blob/master/src/cli/commands/files/add.js#L62, so that if the daemon is on, it doesn't fail. On that, it also needs cli tests to make sure add works when the daemon is on.

@nginnever
Copy link
Member

can be closed in favor of PR

@daviddias
Copy link
Member

ok, thank you for merging them and documenting what is missing, I really like it :)

@daviddias daviddias closed this May 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants