Adds the `tracing` and `md5` crates to the project, enabling enhanced logging and cryptographic hashing capabilities. Includes `TraceLayer` for HTTP request tracing and configures `tracing-subscriber` with `EnvFilter`.
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use crate::schema::users;
|
|
use crate::types::types::OpenSubSonicResponses;
|
|
use crate::{state::AppState, types::types::OpenSubsonicAuth};
|
|
use axum::extract::State;
|
|
use axum::{Json, Router, http::StatusCode, routing::get};
|
|
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
|
|
|
|
pub fn system_routers() -> Router<AppState> {
|
|
Router::new()
|
|
.route(
|
|
"/getOpenSubsonicExtensions.view",
|
|
get(get_opensubsonic_extensions).post(get_opensubsonic_extensions),
|
|
)
|
|
.route("/ping.view", get(ping).post(ping))
|
|
.route("/license.view", get(license).post(license))
|
|
}
|
|
|
|
async fn license(
|
|
State(db_con): State<AppState>,
|
|
user: OpenSubsonicAuth,
|
|
) -> (StatusCode, Json<OpenSubSonicResponses>) {
|
|
let conn = &mut db_con.pool.get().unwrap();
|
|
let result = users::table
|
|
.select(users::email)
|
|
.filter(users::username.eq(user.username))
|
|
.first::<String>(conn);
|
|
match result {
|
|
Ok(e) => (
|
|
StatusCode::OK,
|
|
Json(OpenSubSonicResponses::license_response(Some(e))),
|
|
),
|
|
Err(_) => (
|
|
StatusCode::OK,
|
|
Json(OpenSubSonicResponses::license_response(None)),
|
|
),
|
|
}
|
|
}
|
|
|
|
async fn ping(_user: OpenSubsonicAuth) -> (StatusCode, Json<OpenSubSonicResponses>) {
|
|
(
|
|
StatusCode::OK,
|
|
Json(OpenSubSonicResponses::open_subsonic_response()),
|
|
)
|
|
}
|
|
|
|
async fn get_opensubsonic_extensions() -> (StatusCode, Json<OpenSubSonicResponses>) {
|
|
(
|
|
StatusCode::OK,
|
|
Json(OpenSubSonicResponses::open_subsonic_extensions()),
|
|
)
|
|
}
|