use rocket::fs::NamedFile;
use std::path::{Path, PathBuf};
use crate::common::thumbs_dir;

#[get("/<file..>")]
pub async fn get(file: PathBuf) -> Option<NamedFile> {
    let clips_dir = thumbs_dir();

    // 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
    }
}
