diff --git a/api/src/thumbnail.rs b/api/src/thumbnail.rs new file mode 100644 index 0000000..0673b17 --- /dev/null +++ b/api/src/thumbnail.rs @@ -0,0 +1,24 @@ +// THis module basically takes care of the thumnail +use rocket::fs::NamedFile; +use std::path::{Path, PathBuf}; + +#[get("/")] +pub async fn get(file: PathBuf) -> Option { + 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 + } +}