diff --git a/api/src/category.rs b/api/src/category.rs index b3c277c..e49b576 100644 --- a/api/src/category.rs +++ b/api/src/category.rs @@ -1,8 +1,9 @@ use serde::Serialize; use std::fs::DirEntry; +use std::path::Path; use std::io; use rocket::serde::json::Json; -use crate::common::get_clips_dir; +use crate::common::{get_clips_dir, thumbs_dir}; #[derive(Serialize)] pub struct Category { @@ -34,6 +35,24 @@ pub fn get_category_dirs(path: &str) -> std::io::Result> { return Ok(ret); } +pub fn get_category_thumbnail(category: &str) -> std::io::Result { + let pathname = format!("{}{}", thumbs_dir(), &category); + let path = Path::new(&pathname); + println!("Path to use {:?}", path); + // Assume its a directory + let mut ret = "/static/cantfindshit.jpg".to_string(); + for ent in path.read_dir()? { + if let Ok(ent) = ent { + let name = ent.file_name().into_string().unwrap(); + if name == "category-thumbnail.jpg" { + ret = format!("/thumbnail/{}/{}", category, name); + } + } + } + + return Ok(ret); +} + #[get("/categories")] pub fn list() -> Json> { // WARN: misconfigured servers are just going to get shafted and serve up @@ -46,7 +65,10 @@ pub fn list() -> Json> { // That way we can do this blindly without 9999 allocs for d in dirs { let name = d.file_name().to_string_lossy().to_string(); - let thumbnail = format!("/thumbnail/{}/category-thumbnail.jpg", name); + let thumbnail = match get_category_thumbnail(&name) { + Ok(s) => s, + _ => "/static/cantfindshit.jpg".to_string() + }; cats.push(Category {name, thumbnail}); } } diff --git a/api/src/thumbnail.rs b/api/src/thumbnail.rs index 8280318..7176fe9 100644 --- a/api/src/thumbnail.rs +++ b/api/src/thumbnail.rs @@ -19,7 +19,7 @@ pub async fn get(file: PathBuf) -> Option { None => None } } else { - let path = Path::new("static/cantfindshit.gif"); + let path = Path::new("static/cantfindshit.jpg"); return NamedFile::open(path).await.ok(); } } diff --git a/api/static/cantfindshit.gif b/api/static/cantfindshit.gif deleted file mode 100644 index 270cddb..0000000 Binary files a/api/static/cantfindshit.gif and /dev/null differ diff --git a/api/static/cantfindshit.jpg b/api/static/cantfindshit.jpg new file mode 100644 index 0000000..59f704d --- /dev/null +++ b/api/static/cantfindshit.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc7637a1b3f7e75322e3dddb3499931dc9cd57804afbf46c7941e6bc5211d03c +size 21076