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::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::CONFIG;
|
use crate::DB_FILE;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Row {
|
pub struct Row {
|
||||||
@ -18,7 +18,7 @@ type Data = HashMap<String, Row>;
|
|||||||
pub fn get_video(id: &str) -> Option<Row> {
|
pub fn get_video(id: &str) -> Option<Row> {
|
||||||
// Used to fetch video information from the db for client's to request
|
// Used to fetch video information from the db for client's to request
|
||||||
// video and thumbnail files from us
|
// 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");
|
.expect("Unable to read DB_FILE");
|
||||||
let db_data: Data = json::from_str(&db_file)
|
let db_data: Data = json::from_str(&db_file)
|
||||||
.expect("Unable to parse DB_FILE content");
|
.expect("Unable to parse DB_FILE content");
|
||||||
|
@ -5,15 +5,8 @@ use rocket::fs::FileServer;
|
|||||||
mod video;
|
mod video;
|
||||||
mod db;
|
mod db;
|
||||||
|
|
||||||
pub struct BackendConfig {
|
const FILES_ROOT: &'static str = "/opt/clippable";
|
||||||
pub root: &'static str,
|
const DB_FILE: &'static str = "/opt/clippable/db.json";
|
||||||
pub db_file: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
const CONFIG: BackendConfig = BackendConfig {
|
|
||||||
root: "/opt/clippable",
|
|
||||||
db_file: "/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::{CONFIG, VIDEO_BASE_URI, db};
|
use crate::{FILES_ROOT, VIDEO_BASE_URI, db};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use rocket::fs::NamedFile;
|
use rocket::fs::NamedFile;
|
||||||
use rocket_dyn_templates::{Template, context};
|
use rocket_dyn_templates::{Template, context};
|
||||||
|
|
||||||
@ -24,8 +24,10 @@ pub fn index(video_id: &str) -> Template {
|
|||||||
|
|
||||||
|
|
||||||
#[get("/<path>")]
|
#[get("/<path>")]
|
||||||
pub async fn file(path: PathBuf) -> String {
|
pub async fn file(path: PathBuf) -> Option<NamedFile> {
|
||||||
let path = path.to_str().unwrap_or("");
|
let mut disk = Path::new(FILES_ROOT).join(VIDEO_BASE_URI);
|
||||||
println!("{}", path);
|
disk.push(path);
|
||||||
format!("{}{VIDEO_BASE_URI}/{path}", CONFIG.root)
|
|
||||||
|
println!("disk path: {disk:?}");
|
||||||
|
NamedFile::open(disk).await.ok()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user