synthwave/src/main.rs

54 lines
1.4 KiB
Rust
Raw Normal View History

2024-07-24 09:07:24 +00:00
use library::Libary;
mod library;
mod route;
2024-08-01 12:55:31 +00:00
use library::user::{User, UserRole};
2024-07-24 09:07:24 +00:00
use rocket::routes;
use rocket::{http::Method, launch};
#[launch]
async fn rocket() -> _ {
2024-08-02 14:12:33 +00:00
env_logger::init();
2024-07-24 09:07:24 +00: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");
2024-08-02 14:18:01 +00:00
let lib = Libary::new("./media".into()).await;
2024-07-24 09:07:24 +00:00
lib.rescan().await;
2024-07-28 14:12:06 +00:00
User::create("admin", "admin", UserRole::Admin).await;
2024-07-24 09:07:24 +00:00
rocket::build()
.mount(
"/",
routes![
2024-08-01 14:42:58 +00:00
route::index_redir,
2024-08-07 19:56:09 +00:00
route::manifest_redir,
2024-07-24 09:07:24 +00:00
route::artist::artists_route,
route::artist::artist_route,
2024-08-07 21:07:08 +00:00
route::artist::artist_image_route,
2024-07-24 09:07:24 +00:00
route::album::albums_route,
route::album::album_route,
route::track::track_route,
route::track::track_audio_route,
2024-07-28 14:12:06 +00:00
route::album::album_cover_route,
2024-08-01 12:55:31 +00:00
route::user::login_route,
route::track::track_audio_opus128_route
2024-07-24 09:07:24 +00:00
],
)
.manage(lib)
.attach(cors)
}