use std::path::{Path, PathBuf};

use rocket::fs::NamedFile;

pub fn routes() -> Vec<rocket::Route> {
    routes![profile_pic, general]
}

#[get("/profile/<user_id>")]
pub async fn profile_pic(user_id: usize) -> Option<NamedFile> {
    if let Ok(image) =
        NamedFile::open(Path::new("./cdn/profiles/").join(format!("{}.jpg", user_id))).await
    {
        Some(image)
    } else {
        Some(NamedFile::open("./cdn/profiles/default.svg").await.ok()?)
    }
}

#[get("/<file_name..>")]
pub async fn general(file_name: PathBuf) -> Option<NamedFile> {
    NamedFile::open(Path::new("./cdn/").join(file_name))
        .await
        .ok()
}
