unjs / ipx

πŸ–ΌοΈ High performance, secure and easy-to-use image optimizer.
MIT License
1.2k stars 59 forks source link

fix: improve data parsing for unstorage #204

Closed Aareksio closed 5 months ago

Aareksio commented 6 months ago

πŸ”— Linked issue

https://github.com/nuxt/image/pull/1177

❓ Type of change

πŸ“š Description

The prefix should not be required.

unstorage is not opinionated about what data type should getItem / getItemRaw return (https://github.com/unjs/unstorage/issues/142). This making creating generic wrapper a bit complicated. Since ipx requires the data to be a Buffer, I've added a simple parse attempt in order to normalize error for unsupported storages. The common return data types should be covered: ArrayBuffer, Buffer, String and Blob.


I also found some inconsistencies in unstorage drivers, namely http driver throws 404 when a file is not found, instead of returning null which seems to be unstorage convention. This breaks the test. I classify this as a bug in unstorage and keep the test disabled. Run TEST_UNSTORAGE_HTTP=true pnpm test to see the error.

Screenshot 2024-01-06 at 13 31 47

πŸ“ Checklist

Unstorage support is not documented yet

codecov[bot] commented 5 months ago

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (39c7199) 50.73% compared to head (7df105c) 53.66%.

:exclamation: Current head 7df105c differs from pull request most recent head aefac26. Consider uploading reports for the commit aefac26 to get more accurate results

Files Patch % Lines
src/storage/unstorage.ts 80.00% 7 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #204 +/- ## ========================================== + Coverage 50.73% 53.66% +2.93% ========================================== Files 14 14 Lines 1157 1187 +30 Branches 48 66 +18 ========================================== + Hits 587 637 +50 + Misses 567 547 -20 Partials 3 3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

pi0 commented 5 months ago

Thanks!