refactor mime type support detection in image loader to allow for deferred handling and appended encoding info (#5686)

as recommended by @lucasmerlin in #5679

* Closes #5679
* [x] I have followed the instructions in the PR template
This commit is contained in:
Markus Krause 2025-03-18 11:51:00 +01:00 committed by GitHub
parent 6b38fd39a1
commit 1aced06e47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 4 deletions

View File

@ -36,11 +36,21 @@ fn is_supported_uri(uri: &str) -> bool {
}
fn is_supported_mime(mime: &str) -> bool {
// This is the default mime type for binary files, so this might actually be a valid image,
// let's relay on image's format guessing
if mime == "application/octet-stream" {
return true;
// some mime types e.g. reflect binary files or mark the content as a download, which
// may be a valid image or not, in this case, defer the decision on the format guessing
// or the image crate and return true here
let mimes_to_defer = [
"application/octet-stream",
"application/x-msdownload",
"application/force-download",
];
for m in &mimes_to_defer {
// use contains instead of direct equality, as e.g. encoding info might be appended
if mime.contains(m) {
return true;
}
}
// Uses only the enabled image crate features
ImageFormat::all()
.filter(ImageFormat::reading_enabled)