synthwave/src/main.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

2024-07-24 09:07:24 +00:00
use library::Libary;
mod library;
mod route;
use rocket::routes;
use rocket::{http::Method, launch};
2024-07-28 14:12:06 +00:00
use library::user::{User, UserRole};
2024-07-24 09:07:24 +00:00
#[launch]
async fn rocket() -> _ {
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 lib = Libary::new("/Users/angelo/Downloads/Music".into()).await;
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![
route::artist::artists_route,
route::artist::artist_route,
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,
route::user::login_route
2024-07-24 09:07:24 +00:00
],
)
.manage(lib)
.attach(cors)
}