use based::auth::{User, UserRole}; use based::get_pg; use based::request::cache; use library::Libary; use rocket::routes; use rocket::{http::Method, launch}; mod library; mod route; #[launch] async fn rocket() -> _ { env_logger::init(); 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 pg = get_pg!(); sqlx::migrate!("./migrations").run(pg).await.unwrap(); let lib = Libary::new("./media".into()); let cache = cache::RouteCache::new(); lib.rescan(&cache).await; // create initial admin user if User::find("admin").await.is_none() { User::create("admin", "admin", UserRole::Admin).await; } rocket::build() .mount( "/", routes![ route::index_redir, route::manifest_redir, route::artist::artists_route, route::artist::artist_route, route::artist::artist_image_route, route::album::albums_route, route::album::album_route, route::album::latest_albums_route, route::track::track_route, route::track::track_audio_route, route::track::track_reload_meta_route, route::album::album_cover_route, route::user::login_route, route::user::passwd_route, route::user::user_create_route, route::user::users_route, route::track::track_audio_opus128_route, route::track::track_audio_aac128_route, route::playlist::playlists_route, route::playlist::playlist_route, route::playlist::playlist_add_route, route::playlist::playlist_edit_route, route::playlist::playlist_tracks_route, route::admin::clean_library, route::admin::get_orphans_route, route::admin::get_singles_route, route::event::event_report_route, route::search::search_route, route::track::track_lyrics_route ], ) .manage(lib) .manage(cache) .attach(cors) }