From b13270802fa7ebad2880381f80e42141ca51f6d5 Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 12 Oct 2021 11:19:31 -0700 Subject: [PATCH] + THumbnail API code This is all served behind /thumbail/... --- api/src/thumbnail.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 api/src/thumbnail.rs 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 + } +}