+ THumbnail API code
This is all served behind /thumbail/...
This commit is contained in:
parent
5836258c25
commit
b13270802f
24
api/src/thumbnail.rs
Normal file
24
api/src/thumbnail.rs
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user