diff --git a/service/src/db.rs b/service/src/db.rs index 84c33ba..6a56c37 100644 --- a/service/src/db.rs +++ b/service/src/db.rs @@ -4,7 +4,7 @@ use rocket::serde::json; use serde::Deserialize; use serde::Serialize; -use crate::CONFIG; +use crate::DB_FILE; #[derive(Serialize, Deserialize)] pub struct Row { @@ -18,7 +18,7 @@ type Data = HashMap; pub fn get_video(id: &str) -> Option { // Used to fetch video information from the db for client's to request // video and thumbnail files from us - let db_file = fs::read_to_string(CONFIG.db_file) + let db_file = fs::read_to_string(DB_FILE) .expect("Unable to read DB_FILE"); let db_data: Data = json::from_str(&db_file) .expect("Unable to parse DB_FILE content"); diff --git a/service/src/main.rs b/service/src/main.rs index 10793a0..99f9aaa 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -5,15 +5,8 @@ use rocket::fs::FileServer; mod video; mod db; -pub struct BackendConfig { - pub root: &'static str, - pub db_file: &'static str, -} - -const CONFIG: BackendConfig = BackendConfig { - root: "/opt/clippable", - db_file: "/opt/clippable/db.json" -}; +const FILES_ROOT: &'static str = "/opt/clippable"; +const DB_FILE: &'static str = "/opt/clippable/db.json"; const VIDEO_BASE_URI: &'static str = "/file/video"; diff --git a/service/src/video.rs b/service/src/video.rs index a9d40a0..814f721 100644 --- a/service/src/video.rs +++ b/service/src/video.rs @@ -1,5 +1,5 @@ -use crate::{CONFIG, VIDEO_BASE_URI, db}; -use std::path::PathBuf; +use crate::{FILES_ROOT, VIDEO_BASE_URI, db}; +use std::path::{Path, PathBuf}; use rocket::fs::NamedFile; use rocket_dyn_templates::{Template, context}; @@ -24,8 +24,10 @@ pub fn index(video_id: &str) -> Template { #[get("/")] -pub async fn file(path: PathBuf) -> String { - let path = path.to_str().unwrap_or(""); - println!("{}", path); - format!("{}{VIDEO_BASE_URI}/{path}", CONFIG.root) +pub async fn file(path: PathBuf) -> Option { + let mut disk = Path::new(FILES_ROOT).join(VIDEO_BASE_URI); + disk.push(path); + + println!("disk path: {disk:?}"); + NamedFile::open(disk).await.ok() } \ No newline at end of file