87 lines
2.5 KiB
Rust
87 lines
2.5 KiB
Rust
use based::{asset::AssetRoutes, auth::User, get_pg, ui::components::prelude::Shell};
|
|
use rocket::{http::Method, routes};
|
|
use std::path::Path;
|
|
mod config;
|
|
mod library;
|
|
mod meta;
|
|
mod pages;
|
|
mod yt_meta;
|
|
use based::ui::prelude::*;
|
|
|
|
#[rocket::launch]
|
|
async fn launch() -> _ {
|
|
std::env::set_var("RUST_LOG", "info");
|
|
std::env::set_var("RUST_BACKTRACE", "1");
|
|
env_logger::init();
|
|
|
|
let conf: config::Config =
|
|
toml::from_str(&std::fs::read_to_string("config.toml").unwrap()).unwrap();
|
|
|
|
let dir_path = conf.general.video_path.clone();
|
|
|
|
let pg = get_pg!();
|
|
|
|
sqlx::migrate!("./migrations").run(pg).await.unwrap();
|
|
|
|
let lib = library::Library::new().await;
|
|
|
|
User::create("admin".to_string(), "admin", based::auth::UserRole::Admin).await;
|
|
|
|
let library = lib.clone();
|
|
|
|
let handle = tokio::spawn(async move {
|
|
library
|
|
.scan_dir(&Path::new(&dir_path.clone()).to_path_buf())
|
|
.await;
|
|
});
|
|
|
|
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");
|
|
|
|
let shell = Shell::new(
|
|
Nothing(),
|
|
Nothing(),
|
|
Background(Text("").white()).color(Colors::Black),
|
|
)
|
|
.use_ui();
|
|
|
|
rocket::build()
|
|
.mount_assets()
|
|
.mount(
|
|
"/",
|
|
routes![
|
|
pages::assets::video_file,
|
|
pages::assets::video_thumbnail,
|
|
pages::assets::fav_icon,
|
|
pages::index::search,
|
|
pages::index::dir_page,
|
|
pages::yt::yt_tags,
|
|
pages::yt::yt_tag_page,
|
|
pages::yt::yt_channel_page,
|
|
pages::index::index_page,
|
|
pages::watch::watch_page,
|
|
pages::user::login,
|
|
pages::user::login_post,
|
|
pages::user::history_page,
|
|
pages::index::latest_page,
|
|
pages::index::latest_api,
|
|
pages::user::account,
|
|
pages::user::change_password,
|
|
pages::user::change_password_post
|
|
],
|
|
)
|
|
.attach(cors)
|
|
.manage(lib)
|
|
.manage(conf)
|
|
.manage(shell)
|
|
}
|