* Category thumbnails are no longer awful

shug.jpg has entered the chat
This commit is contained in:
shockrah 2021-10-21 00:19:24 -07:00
parent f42f125766
commit c74ee022fc
4 changed files with 28 additions and 3 deletions

View File

@ -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<Vec<DirEntry>> {
return Ok(ret);
}
pub fn get_category_thumbnail(category: &str) -> std::io::Result<String> {
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<Vec<Category>> {
// WARN: misconfigured servers are just going to get shafted and serve up
@ -46,7 +65,10 @@ pub fn list() -> Json<Vec<Category>> {
// 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});
}
}

View File

@ -19,7 +19,7 @@ pub async fn get(file: PathBuf) -> Option<NamedFile> {
None => None
}
} else {
let path = Path::new("static/cantfindshit.gif");
let path = Path::new("static/cantfindshit.jpg");
return NamedFile::open(path).await.ok();
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 MiB

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bc7637a1b3f7e75322e3dddb3499931dc9cd57804afbf46c7941e6bc5211d03c
size 21076