next-image-export-optimizer icon indicating copy to clipboard operation
next-image-export-optimizer copied to clipboard

fix: add support for external images with query params

Open mmtftr opened this issue 1 year ago • 3 comments

mmtftr avatar Feb 21 '24 12:02 mmtftr

The library didn't work with external images that had URLs with query parameters since it encoded them into the extension, thus making it impossible to know the extension in React.

Problem demonstration

console.log(urlToFilename('https://example.com/image.png?asd=123')) // -> 'example.com_image.png_asd=123'

'png_asd=123' is not a valid extension, so the React component falls back to the original URL, basically making it meaningless to use the library.

My change

My change adds the '.png' back into the filename at the end when there is a nonempty search query.

mmtftr avatar Feb 21 '24 12:02 mmtftr

@Niels-IO I think this might be a useful fix for a lot of people, especially those that use google storage images with presigned keys

mmtftr avatar Apr 06 '24 08:04 mmtftr

Hi @mmtftr,

Thanks for the PR!. I will take a look but it might take me until May as I am quite busy now.

Niels-IO avatar Apr 07 '24 08:04 Niels-IO

Hi @mmtftr,

Thank you very much for your PR. I changed the remote Image functionality quite a bit and your code did help me a lot. I integrated it in #220.

Hopefully, you don't mind that I didn't merge your PR directly.

Niels-IO avatar Jun 09 '24 20:06 Niels-IO