2024-07-24 09:07:24 +00:00
|
|
|
use library::Libary;
|
|
|
|
|
2024-08-08 11:06:02 +00:00
|
|
|
mod cache;
|
2024-07-24 09:07:24 +00:00
|
|
|
mod library;
|
|
|
|
mod route;
|
|
|
|
|
2024-08-01 12:55:31 +00:00
|
|
|
use library::user::{User, UserRole};
|
2024-08-11 00:57:16 +00:00
|
|
|
use mongod::Model;
|
|
|
|
use mongodb::bson::doc;
|
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-12 16:48:33 +00:00
|
|
|
let lib = Libary::new("./media".into());
|
2024-08-12 23:26:55 +00:00
|
|
|
let cache = cache::RouteCache::new();
|
2024-07-24 09:07:24 +00:00
|
|
|
|
2024-08-12 23:26:55 +00:00
|
|
|
lib.rescan(&cache).await;
|
2024-07-24 09:07:24 +00:00
|
|
|
|
2024-08-11 00:57:16 +00:00
|
|
|
// create initial admin user
|
2024-08-16 18:42:02 +00:00
|
|
|
if User::find(doc! { "username": "admin" }, None, None)
|
2024-08-11 00:57:16 +00:00
|
|
|
.await
|
|
|
|
.is_none()
|
|
|
|
{
|
|
|
|
User::create("admin", "admin", UserRole::Admin).await;
|
|
|
|
}
|
2024-07-28 14:12:06 +00:00
|
|
|
|
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,
|
2024-08-12 23:26:55 +00:00
|
|
|
route::album::latest_albums_route,
|
2024-07-24 09:07:24 +00:00
|
|
|
route::track::track_route,
|
|
|
|
route::track::track_audio_route,
|
2024-08-12 23:52:16 +00:00
|
|
|
route::track::track_reload_meta_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,
|
2024-08-08 12:28:23 +00:00
|
|
|
route::user::passwd_route,
|
|
|
|
route::user::user_create_route,
|
2024-08-11 00:57:16 +00:00
|
|
|
route::user::users_route,
|
2024-08-11 02:07:02 +00:00
|
|
|
route::track::track_audio_opus128_route,
|
2024-08-15 14:45:04 +00:00
|
|
|
route::track::track_audio_aac128_route,
|
2024-08-11 02:07:02 +00:00
|
|
|
route::playlist::playlists_route,
|
2024-08-11 19:56:55 +00:00
|
|
|
route::playlist::playlist_route,
|
|
|
|
route::playlist::playlist_add_route,
|
2024-08-12 01:43:08 +00:00
|
|
|
route::playlist::playlist_edit_route,
|
2024-08-12 23:52:16 +00:00
|
|
|
route::playlist::playlist_tracks_route,
|
2024-08-16 10:24:02 +00:00
|
|
|
route::admin::clean_library,
|
|
|
|
route::admin::get_orphans_route,
|
|
|
|
route::admin::get_singles_route
|
2024-07-24 09:07:24 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
.manage(lib)
|
2024-08-08 11:06:02 +00:00
|
|
|
.manage(cache)
|
2024-07-24 09:07:24 +00:00
|
|
|
.attach(cors)
|
|
|
|
}
|