Path & PathBuf .join() methods are more headache than they're worth
Here's two hard coded variables
This commit is contained in:
parent
7d813391bd
commit
eb99d97e7b
@ -5,7 +5,7 @@ use rocket::fs::FileServer;
|
|||||||
mod video;
|
mod video;
|
||||||
mod db;
|
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 DB_FILE: &'static str = "/opt/clippable/db.json";
|
||||||
const VIDEO_BASE_URI: &'static str = "/file/video";
|
const VIDEO_BASE_URI: &'static str = "/file/video";
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{FILES_ROOT, VIDEO_BASE_URI, db};
|
use crate::{FILES_VIDEO, VIDEO_BASE_URI, db};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::PathBuf;
|
||||||
use rocket::fs::NamedFile;
|
use rocket::fs::NamedFile;
|
||||||
use rocket_dyn_templates::{Template, context};
|
use rocket_dyn_templates::{Template, context};
|
||||||
|
|
||||||
@ -25,8 +25,7 @@ pub fn index(video_id: &str) -> Template {
|
|||||||
|
|
||||||
#[get("/<path>")]
|
#[get("/<path>")]
|
||||||
pub async fn file(path: PathBuf) -> Option<NamedFile> {
|
pub async fn file(path: PathBuf) -> Option<NamedFile> {
|
||||||
let mut disk = Path::new(FILES_ROOT).join(VIDEO_BASE_URI);
|
let disk = PathBuf::from(FILES_VIDEO).join(path);
|
||||||
disk.push(path);
|
|
||||||
|
|
||||||
println!("disk path: {disk:?}");
|
println!("disk path: {disk:?}");
|
||||||
NamedFile::open(disk).await.ok()
|
NamedFile::open(disk).await.ok()
|
||||||
|
Loading…
Reference in New Issue
Block a user