use crate::{CONFIG, VIDEO_BASE_URI, db}; use std::path::PathBuf; use rocket::fs::NamedFile; use rocket_dyn_templates::{Template, context}; #[get("/")] pub fn index(video_id: &str) -> Template { // Read the db file we have to get the ID // Now we can fetch the row from the DB content match db::get_video(video_id) { Some(video) => { let path = PathBuf::from(&video.file); Template::render("video", context! { title: path.to_str().unwrap(), kind: path.extension().expect("No extension found").to_str().unwrap(), video: format!("{}/{}", VIDEO_BASE_URI, video.file) }) }, None => Template::render("video", context! { title: "Not found" }) } } #[get("/")] pub async fn file(path: PathBuf) -> String { let path = path.to_str().unwrap_or(""); println!("{}", path); format!("{}{VIDEO_BASE_URI}/{path}", CONFIG.root) }