* Category thumbnails are no longer awful
shug.jpg has entered the chat
This commit is contained in:
parent
f42f125766
commit
c74ee022fc
@ -1,8 +1,9 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fs::DirEntry;
|
use std::fs::DirEntry;
|
||||||
|
use std::path::Path;
|
||||||
use std::io;
|
use std::io;
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use crate::common::get_clips_dir;
|
use crate::common::{get_clips_dir, thumbs_dir};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Category {
|
pub struct Category {
|
||||||
@ -34,6 +35,24 @@ pub fn get_category_dirs(path: &str) -> std::io::Result<Vec<DirEntry>> {
|
|||||||
return Ok(ret);
|
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")]
|
#[get("/categories")]
|
||||||
pub fn list() -> Json<Vec<Category>> {
|
pub fn list() -> Json<Vec<Category>> {
|
||||||
// WARN: misconfigured servers are just going to get shafted and serve up
|
// 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
|
// That way we can do this blindly without 9999 allocs
|
||||||
for d in dirs {
|
for d in dirs {
|
||||||
let name = d.file_name().to_string_lossy().to_string();
|
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});
|
cats.push(Category {name, thumbnail});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ pub async fn get(file: PathBuf) -> Option<NamedFile> {
|
|||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let path = Path::new("static/cantfindshit.gif");
|
let path = Path::new("static/cantfindshit.jpg");
|
||||||
return NamedFile::open(path).await.ok();
|
return NamedFile::open(path).await.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.8 MiB |
3
api/static/cantfindshit.jpg
Normal file
3
api/static/cantfindshit.jpg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:bc7637a1b3f7e75322e3dddb3499931dc9cd57804afbf46c7941e6bc5211d03c
|
||||||
|
size 21076
|
Loading…
Reference in New Issue
Block a user