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

[gatsby-source-filesystem] createRemoteFileNode: Keep original name #9539

Closed
LekoArts opened this issue Oct 29, 2018 · 9 comments
Closed

[gatsby-source-filesystem] createRemoteFileNode: Keep original name #9539

LekoArts opened this issue Oct 29, 2018 · 9 comments
Labels
help wanted Issue with a clear description that the community can help with. stale? Issue that may be closed soon due to the original author not responding any more.

Comments

@LekoArts
Copy link
Contributor

LekoArts commented Oct 29, 2018

Summary

Since this issue (#6232) was fixed by @Sekhmet only one thing is left: Also keep the original file name in the downloaded image (as per old issue #3132). Other requests: prismicio/prismic-gatsby#40

@Sekhmet do you want to tackle that issue, too?

A result should be, e.g.:

  • filepath:
    /static/f28264fbe0c2cf6d02c3b8adc54b717b/18b00/e10dce13ec246d93bf6e57ede0d98ce8.jpg
  • new filepath:
    /static/f28264fbe0c2cf6d02c3b8adc54b717b/18b00/e10dce13ec246d93bf6e57ede0d98ce8/this-is-the-super-name-here.jpg
@LekoArts LekoArts added help wanted Issue with a clear description that the community can help with. type: feature or enhancement labels Oct 29, 2018
@hbish
Copy link
Contributor

hbish commented Oct 31, 2018

I'll have a go at this.

@jkjustjoshing
Copy link
Contributor

jkjustjoshing commented Nov 7, 2018

What's the practicality of allowing the hash to be customizable too (or fully remove for non-duplicate filenames?)?

I'm moving a site over that has a bunch of PDFs on it. I'm using gatsby-source-directus to pull down the PDFs from my Directus server, which uses createRemoteFileNode() to add the files to Gatsby.

Our current PDF urls look something like this - https://www.example.com/static/Financial_Disclosure_Form.pdf - and the users frequently will use ⌘+S to save the PDFs. Right now, this causes the default filename to be the MD5 hash of the file 79054025255fb1a26e4bc422aef54eb4.pdf, not Financial_Disclosure_Form.pdf.

It looks like PR #9777 will make it so the filename is 79054025255fb1a26e4bc422aef54eb4-Financial_Disclosure_Form.pdf, which is also not acceptable to me. Would it be possible to do one (or all) of the following?

  1. Put the hash at the end - Financial_Disclosure_Form-79054025255fb1a26e4bc422aef54eb4.pdf
  2. Allow for a shorter hash length (and throw an exception if there is a conflict) - Financial_Disclosure_Form-79054.pdf
  3. Allow for no hash if there is no filename conflict (how easy will it be to detect filename conflicts vs one file requested twice?)
  4. Allow for createRemoteFileNode to accept an optional callback that takes the name and the hash (and potentially a list of all other defined files, to avoid duplicates?) as the parameters and returns the filename to be used.

Do any of those ideas seam feasible?

@hbish
Copy link
Contributor

hbish commented Nov 8, 2018

Hey @jkjustjoshing

I think what you've proposed for (1) is reasonable and makes total sense to have the filename first.

With regards to (2) & (3), I think there are different use cases based on the source. For images, the filename may not mean as much compared to downloadable content like documents. So we could add an optional parameter to createRemoteFileNode toggle between hash and no hash and let plugin implementer choose.

As to (4), I'm a little unclear by this one, could you please elaborate a bit more on what you mean a list of all other defined file? and maybe provide an example of what you envision?

Keen to hear what others think.

@pieh
Copy link
Contributor

pieh commented Nov 8, 2018

I think we could keep original filename and just put file in directory with hash.

@jkjustjoshing How are you referencing files when constructing download links - using query and publicURL?

@jkjustjoshing
Copy link
Contributor

#4 would be a way to fully customize the filename while still avoiding collisions - if the callback is passed a list of all other files the plugin implementer could check for duplicates and ensure any potential collisions are avoided.

I really like your suggestion @pieh, putting a file in a folder with the hash (potentially doing so only when a flag is passed to createRemoteFileNode()). I am referencing the files using query and publicURL, so any change will work for me. This fully solves my filename problem and the problem of potential collisions

Are there any performance implications for projects with a very large number of files to having 1 folder per file?

@hbish
Copy link
Contributor

hbish commented Nov 23, 2018

Sorry just got back from an overseas holiday, I've updated the PR so that files are stored in directories of the hash. e.g. hash/filename.ext. Original filename and extensions are maintained.

@jkjustjoshing
Copy link
Contributor

Awesome! Thanks for your work on this!

@gatsbot
Copy link

gatsbot bot commented Feb 3, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Feb 3, 2019
@LekoArts
Copy link
Contributor Author

LekoArts commented Feb 3, 2019

Fixed with #9777

@LekoArts LekoArts closed this as completed Feb 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with. stale? Issue that may be closed soon due to the original author not responding any more.
Projects
None yet
Development

No branches or pull requests

4 participants