2025-02-09 07:09:20 +01:00
|
|
|
use based::{
|
|
|
|
asset::AssetRoutes,
|
|
|
|
auth::User,
|
|
|
|
get_pg,
|
|
|
|
ui::components::{AppBar, Shell},
|
|
|
|
};
|
2024-10-05 01:21:43 +02:00
|
|
|
use rocket::{http::Method, routes};
|
2024-12-18 19:24:38 +01:00
|
|
|
use std::path::Path;
|
2025-02-09 07:09:20 +01:00
|
|
|
mod config;
|
2023-10-06 18:29:55 +02:00
|
|
|
mod library;
|
2024-12-16 23:45:15 +01:00
|
|
|
mod meta;
|
2023-10-06 18:29:55 +02:00
|
|
|
mod pages;
|
|
|
|
mod yt_meta;
|
2025-02-09 07:09:20 +01:00
|
|
|
use based::ui::prelude::*;
|
2023-10-06 18:29:55 +02:00
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
#[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();
|
|
|
|
|
2025-02-09 07:09:20 +01:00
|
|
|
let conf: config::Config =
|
|
|
|
toml::from_str(&std::fs::read_to_string("config.toml").unwrap()).unwrap();
|
2023-10-06 18:29:55 +02:00
|
|
|
|
2025-02-09 07:09:20 +01:00
|
|
|
let dir_path = conf.general.video_path.clone();
|
2023-10-06 18:29:55 +02:00
|
|
|
|
2024-10-07 09:24:54 +02:00
|
|
|
let pg = get_pg!();
|
|
|
|
|
|
|
|
sqlx::migrate!("./migrations").run(pg).await.unwrap();
|
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
let lib = library::Library::new().await;
|
2024-12-16 21:16:02 +01:00
|
|
|
|
2024-12-29 21:39:54 +01:00
|
|
|
User::create("admin".to_string(), "admin", based::auth::UserRole::Admin).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-12-14 21:50:49 +01:00
|
|
|
let handle = tokio::spawn(async move {
|
|
|
|
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");
|
|
|
|
|
2025-02-09 07:09:20 +01:00
|
|
|
let shell = Shell::new(
|
|
|
|
Nothing(),
|
|
|
|
Nothing(),
|
|
|
|
Background(Text("").white()).color(Colors::Black),
|
|
|
|
)
|
|
|
|
.use_ui();
|
|
|
|
|
2024-10-05 01:21:43 +02:00
|
|
|
rocket::build()
|
2025-01-22 19:10:33 +01:00
|
|
|
.mount_assets()
|
2024-10-07 09:24:54 +02:00
|
|
|
.mount(
|
|
|
|
"/",
|
|
|
|
routes![
|
|
|
|
pages::assets::video_file,
|
|
|
|
pages::assets::video_thumbnail,
|
2024-12-15 00:31:39 +01:00
|
|
|
pages::assets::fav_icon,
|
2024-10-07 09:24:54 +02:00
|
|
|
pages::index::search,
|
2025-01-22 19:10:33 +01:00
|
|
|
pages::index::dir_page,
|
2024-10-07 09:24:54 +02:00
|
|
|
pages::yt::yt_tags,
|
|
|
|
pages::yt::yt_tag_page,
|
2024-12-14 00:24:10 +01:00
|
|
|
pages::yt::yt_channel_page,
|
|
|
|
pages::index::index_page,
|
2024-12-16 21:16:02 +01:00
|
|
|
pages::watch::watch_page,
|
|
|
|
pages::user::login,
|
2024-12-22 20:19:52 +01:00
|
|
|
pages::user::login_post,
|
2024-12-29 21:49:48 +01:00
|
|
|
pages::user::history_page,
|
|
|
|
pages::index::latest_page,
|
|
|
|
pages::index::latest_api
|
2024-10-07 09:24:54 +02:00
|
|
|
],
|
|
|
|
)
|
2024-10-05 01:21:43 +02:00
|
|
|
.attach(cors)
|
|
|
|
.manage(lib)
|
2025-02-09 07:09:20 +01:00
|
|
|
.manage(conf)
|
|
|
|
.manage(shell)
|
2023-10-06 18:29:55 +02:00
|
|
|
}
|