Path & PathBuf .join() methods are more headache than they're worth

Here's two hard coded variables
This commit is contained in:
shockrah 2025-08-17 15:30:09 -07:00
parent 7d813391bd
commit eb99d97e7b
2 changed files with 4 additions and 5 deletions

View File

@ -5,7 +5,7 @@ use rocket::fs::FileServer;
mod video;
mod db;
const FILES_ROOT: &'static str = "/opt/clippable";
const FILES_VIDEO: &'static str = "/opt/clippable/file/video";
const DB_FILE: &'static str = "/opt/clippable/db.json";
const VIDEO_BASE_URI: &'static str = "/file/video";

View File

@ -1,5 +1,5 @@
use crate::{FILES_ROOT, VIDEO_BASE_URI, db};
use std::path::{Path, PathBuf};
use crate::{FILES_VIDEO, VIDEO_BASE_URI, db};
use std::path::PathBuf;
use rocket::fs::NamedFile;
use rocket_dyn_templates::{Template, context};
@ -25,8 +25,7 @@ pub fn index(video_id: &str) -> Template {
#[get("/<path>")]
pub async fn file(path: PathBuf) -> Option<NamedFile> {
let mut disk = Path::new(FILES_ROOT).join(VIDEO_BASE_URI);
disk.push(path);
let disk = PathBuf::from(FILES_VIDEO).join(path);
println!("disk path: {disk:?}");
NamedFile::open(disk).await.ok()