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] support remote urls with GET query #2985

Closed
wants to merge 2 commits into from

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Nov 21, 2017

Currently gatsby would fail to build (at least on windows) when using createRemoteFileNode (imported from gatsby-source-filesystem) with URL that contains GET query (f.e. some images from facebook graph api - https://external.xx.fbcdn.net/safe_image.php?d=AQAcMebX6qD2g7NL&url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FcwGbD7OgvM8uI%2Fgiphy.gif&_nc_hash=AQB7E1MjiB7Vhee6 ).

It's because path.parse(url).ext (used to build both tmpFilename and final filename) would return extension with GET query attached (using my example .php?d=[...]) and question mark is illegal character in windows filename (pretty sure it can cause troubles on linux too).

After fixing that, there is issue that gatsby-source-filesystem set MIME type from extension and .php obviously won't get correct image type and thus will not allow to use image transformer plugins. So in case of not detecting type from extension (checking for general application/octet-stream as per mime module documentation - https://github.com/broofa/node-mime/tree/v1.4.0#mimelookuppath) this will try to figure out MIME type / extension with file-type package.

This is Request for comments! for now. It wasn't tested in this form (I duplicated createRemoteFileNode function in my source plugin and got this to work)

@gatsbybot
Copy link
Collaborator

Deploy preview ready!

Built with commit e70511f

https://deploy-preview-2985--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview ready!

Built with commit e70511f

https://deploy-preview-2985--using-drupal.netlify.com

@calcsam
Copy link
Contributor

calcsam commented Nov 27, 2017

Looks like re: your example this will strip the whole extension after .php, giving the file a .php extension instead of .jpg.

It seems like one path that would work is to leave the extension as is, and sanitize the resulting extension with eg https://www.npmjs.com/package/sanitize-filename.

Other solutions are possible in the future, eg smarter filename detection but should probably stick with a simpler version to start w/.

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit 2271b6f

https://app.netlify.com/sites/using-glamor/deploys/5a1c3feb8198766f5eb71261

@pieh
Copy link
Contributor Author

pieh commented Nov 27, 2017

@calcsam
Yeah, sanitizing is definitely better than stripping of query. It will help with making extension actually not represent something that file is not - that image definitely is not .php file so propably better to use some giberish extension. I also noticed that my commit actually wouldn't work cause MIME type from .php extension file would be application/x-php and would never check magic number .

I'll update code when i will have time to actually test it.

@pieh
Copy link
Contributor Author

pieh commented Dec 11, 2017

I'll close this for now - used alternative solution so I didn't pursue this more and don't have time now prepare and test better solution.

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