Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds self served directory listings #323

Merged
merged 12 commits into from
Dec 16, 2017
Merged

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Dec 1, 2017

\o/ Directory viewer in Brave for handled ipfs:// requests!

screen shot 2017-12-04 at 09 34 14

screen shot 2017-12-04 at 09 34 22

@alanshaw alanshaw changed the title Adds self served directory listings [WIP] Adds self served directory listings Dec 1, 2017
@@ -36,7 +36,7 @@
"description": "A label in Node status section of Browser Action pop-up"
},
"panel_quickUpload": {
"message": "Quick Upload",
"message": "Share files via IPFS",
Copy link
Member

Choose a reason for hiding this comment

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

I must say, it is a much better name for this feature 👍

package.json Outdated
@@ -69,10 +69,16 @@
},
"dependencies": {
"choo": "6.6.0",
"doc-sniff": "^1.0.1",
Copy link
Member

@lidel lidel Dec 1, 2017

Choose a reason for hiding this comment

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

fyi I've found two ways to avoid the chore of removing ^ from package.json

  • while doing npm install of new dependency, one can do it with --save --save-exact
  • to make it default behaviour globally: npm config set save-exact true

Copy link
Member

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

Dir listing is super neat ✨

As a note to self.... We'll want to extract the trailing slash normalisation logic soon, as it causes issues when trying to render webpages with relative links. I'll raise seperate issue for that.

@olizilla
Copy link
Member

@lidel when you get a moment to look at this pr, this compare view to just check the changes without all of #320 in too, is helpful:

tableflip/ipfs-companion@84b2ada...tableflip:feat/dir-view#diff-ca7aa692aef78b2031d7a5da30e03248R10

@alanshaw alanshaw changed the title [WIP] Adds self served directory listings Adds self served directory listings Dec 12, 2017
try {
data = await ipfs.files.cat(path)
} catch (err) {
if (err.message.toLowerCase() === 'this dag node is a directory') {
Copy link
Member

Choose a reason for hiding this comment

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

Ouch, is this the only way we can detect directories?

Copy link
Member Author

Choose a reason for hiding this comment

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

I probably should have explained this a little...here goes:

It's similar to how the js-ipfs http gateway works. It tries to "resolve" a path (e.g. /ipfs/$hash/path/to/a/file) by using ipfs.dag.get to walk the path and eventually find the hash of the file at the end. It uses Unixfs.unmarshal on the end file to detect a directory and will raise an error if so "this dag node is a directory". If this error occurs then it'll try to get the links using ipfs.object.get and render a directory view.

Instead of walking the path using ipfs.dag.get (which isn't available in js-ipfs-api) we use ipfs.files.cat which has the advantage of being able to pass a path to it (so the walking is done for us) and is what we'd call to get file content anyway. It also returns the same error - "this dag node is a directory" for directories. We use ipfs.ls instead of ipfs.object.get because:

  1. ipfs.files.cat resolved the hash but didn't return it to us so we can't use ipfs.object.get anyway since it needs a hash
  2. We can pass a path to ipfs.ls and it'll give us the links

Is there a better way? @diasdavid

@lidel
Copy link
Member

lidel commented Dec 14, 2017

@alanshaw If you resolve conflict with master, I think we can merge this before it gets cold. 👍

@daviddias
Copy link
Member

🌟

@lidel lidel merged commit 686c648 into ipfs:master Dec 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants