feat: implement robust format identification, plugin availability checks, and automatic conversion path rerouting on failure
Release / check-release (push) Successful in 16s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m52s
CI / Build Linux (push) Successful in 2m0s
Release / check-release (push) Successful in 16s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m52s
CI / Build Linux (push) Successful in 2m0s
This commit is contained in:
1 parent
a372937854
commit
d3b7d7a18f
8 files changed
+244
-97
No files matched your search
+21
-6
@@ -15,14 +15,29 @@
|
||||
use crate::plugin::Plugin;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn identify_format(path: &str, plugins: &[Box<dyn Plugin>]) -> Option<&'static str> {
|
||||
pub fn identify_format(path: &str, input: &[u8], plugins: &[Box<dyn Plugin>]) -> Option<&'static str> {
|
||||
let mut ext_str_opt = None;
|
||||
|
||||
if let Some(kind) = infer::get(input) {
|
||||
ext_str_opt = Some(kind.extension());
|
||||
}
|
||||
|
||||
let p = Path::new(path);
|
||||
let ext = p
|
||||
let mut ext = p
|
||||
.extension()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or(path)
|
||||
.to_lowercase();
|
||||
let ext_str = match ext.as_str() {
|
||||
.map(|s| s.to_lowercase());
|
||||
|
||||
if ext.is_none() {
|
||||
ext = Some(path.to_lowercase());
|
||||
}
|
||||
|
||||
let mut ext_str = ext.as_deref().unwrap_or("");
|
||||
if ext_str_opt.is_some() {
|
||||
ext_str = ext_str_opt.unwrap();
|
||||
}
|
||||
|
||||
let ext_str = match ext_str {
|
||||
"jpg" => "jpeg",
|
||||
other => other,
|
||||
};
|
||||
@@ -61,7 +76,7 @@ mod tests {
|
||||
fn $name() {
|
||||
let mock = Box::new(MockPlugin);
|
||||
let plugins: Vec<Box<dyn Plugin>> = vec![mock];
|
||||
assert_eq!(identify_format($ext, &plugins), $expected);
|
||||
assert_eq!(identify_format($ext, &[], &plugins), $expected);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user