diff --git a/backend/src/thumbnailer.rs b/backend/src/thumbnailer.rs index 7e34a79..2dae378 100644 --- a/backend/src/thumbnailer.rs +++ b/backend/src/thumbnailer.rs @@ -38,14 +38,6 @@ impl Thumbnailer { Ok(t) } - /// Load all thumbanilers available in the system - pub fn load_all() -> Result> { - Ok(fs::read_dir("/usr/share/thumbnailers")? - .filter_map(|f| f.ok()) - .filter_map(|f| Thumbnailer::load(&*f.path()).ok()) - .collect()) - } - /// Check if this thumbnailer should run on a specific mime type pub fn check(&self, mime: &str) -> bool { self.mime_type.contains(mime) @@ -69,3 +61,22 @@ impl Thumbnailer { Ok(()) } } + +pub struct Thumbnailers { + list: Vec +} + +impl Thumbnailers { + /// Load all thumbanilers available in the system + pub fn load_all() -> Result { + Ok(Thumbnailers { list: fs::read_dir("/usr/share/thumbnailers")? + .filter_map(|f| f.ok()) + .filter_map(|f| Thumbnailer::load(&*f.path()).ok()) + .collect() }) + } + + /// Find a thumbnailer for a mime type + pub fn find(&self, mime: &str) -> Option<&Thumbnailer> { + self.list.iter().find(|x| x.check(mime)) + } +}