+ THumbnail API code

This is all served behind /thumbail/...
This commit is contained in:
shockrah 2021-10-12 11:19:31 -07:00
parent 5836258c25
commit b13270802f

24
api/src/thumbnail.rs Normal file
View File

@ -0,0 +1,24 @@
// THis module basically takes care of the thumnail
use rocket::fs::NamedFile;
use std::path::{Path, PathBuf};
#[get("/<file..>")]
pub async fn get(file: PathBuf) -> Option<NamedFile> {
let clips_dir = match std::env::var("THUMBS_DIR") {
Ok(val) => val,
Err(_) => "/media/thumbnails/".to_string()
};
// Only serve jpg's and png's through this route
return match file.extension() {
Some(ext) => {
if ext == "jpg" || ext == "png" || ext == "jpeg" {
println!("Found it");
NamedFile::open(Path::new(&clips_dir).join(file)).await.ok()
} else {
println!("bad extension");
None
}
},
None => None
}
}