Stablizing backend files search
This commit is contained in:
parent
1309ab2324
commit
7d813391bd
@ -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<String, Row>;
|
||||
pub fn get_video(id: &str) -> Option<Row> {
|
||||
// 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");
|
||||
|
@ -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";
|
||||
|
||||
|
||||
|
@ -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("/<path>")]
|
||||
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<NamedFile> {
|
||||
let mut disk = Path::new(FILES_ROOT).join(VIDEO_BASE_URI);
|
||||
disk.push(path);
|
||||
|
||||
println!("disk path: {disk:?}");
|
||||
NamedFile::open(disk).await.ok()
|
||||
}
|
Loading…
Reference in New Issue
Block a user