2023-10-06 18:29:55 +02:00
|
|
|
use std::path::Path;
|
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
use rocket::{http::Method, routes};
|
|
|
|
|
2023-10-06 18:29:55 +02:00
|
|
|
mod library;
|
|
|
|
mod pages;
|
|
|
|
mod yt_meta;
|
|
|
|
|
2024-09-15 04:09:46 +02:00
|
|
|
// TODO : Add User Auth DB
|
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
// TODO : Rework into Video Server Backend
|
|
|
|
// -> API
|
|
|
|
|
|
|
|
#[rocket::launch]
|
|
|
|
async fn launch() -> _ {
|
2023-10-06 18:29:55 +02:00
|
|
|
std::env::set_var("RUST_LOG", "info");
|
|
|
|
std::env::set_var("RUST_BACKTRACE", "1");
|
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
|
|
|
|
if args.len() != 2 {
|
|
|
|
eprintln!("Usage: {} <directory_path>", args[0]);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let dir_path = args[1].clone();
|
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
let lib = library::Library::new().await;
|
2023-10-06 18:29:55 +02:00
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
let library = lib.clone();
|
2023-10-06 18:29:55 +02:00
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
library.scan_dir(&Path::new(&dir_path.clone()).to_path_buf()).await;
|
2023-10-06 18:29:55 +02:00
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
let cors = rocket_cors::CorsOptions {
|
|
|
|
allowed_origins: rocket_cors::AllowedOrigins::all(),
|
|
|
|
allowed_methods: vec![Method::Get, Method::Post, Method::Options]
|
|
|
|
.into_iter()
|
|
|
|
.map(From::from)
|
|
|
|
.collect(),
|
|
|
|
allowed_headers: rocket_cors::AllowedHeaders::all(),
|
|
|
|
allow_credentials: true,
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.to_cors()
|
|
|
|
.expect("error creating CORS options");
|
|
|
|
|
|
|
|
rocket::build()
|
|
|
|
.mount("/", routes![
|
|
|
|
pages::assets::video_file,
|
|
|
|
pages::assets::video_thumbnail,
|
|
|
|
pages::index::search,
|
|
|
|
pages::index::channel_page,
|
|
|
|
pages::yt::yt_tags,
|
|
|
|
pages::yt::yt_tag_page,
|
|
|
|
pages::yt::yt_channel_page
|
|
|
|
])
|
|
|
|
.attach(cors)
|
|
|
|
.manage(lib)
|
2023-10-06 18:29:55 +02:00
|
|
|
}
|