80 lines
2.5 KiB
Rust
80 lines
2.5 KiB
Rust
use library::Libary;
|
|
|
|
mod cache;
|
|
mod library;
|
|
mod route;
|
|
|
|
use library::user::{User, UserRole};
|
|
use mongod::Model;
|
|
use mongodb::bson::doc;
|
|
use rocket::routes;
|
|
use rocket::{http::Method, launch};
|
|
|
|
#[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 lib = Libary::new("./media".into());
|
|
let cache = cache::RouteCache::new();
|
|
|
|
lib.rescan(&cache).await;
|
|
|
|
// create initial admin user
|
|
if User::find(doc! { "username": "admin" }, None, None)
|
|
.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
|
|
],
|
|
)
|
|
.manage(lib)
|
|
.manage(cache)
|
|
.attach(cors)
|
|
}
|