2023-10-08 20:11:59 +00:00
|
|
|
use poem::web::Data;
|
|
|
|
|
use sqlx::SqlitePool;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
authentication::Authentication,
|
|
|
|
|
subsonic::{self, SubsonicResponse},
|
|
|
|
|
user,
|
|
|
|
|
};
|
2023-10-08 19:53:42 +00:00
|
|
|
|
|
|
|
|
#[poem::handler]
|
2023-10-08 20:11:59 +00:00
|
|
|
pub async fn ping(Data(pool): Data<&SqlitePool>, auth: Authentication) -> SubsonicResponse {
|
|
|
|
|
let user = user::get_user(pool, &auth.username).await;
|
2023-10-08 19:53:42 +00:00
|
|
|
|
2023-10-08 20:11:59 +00:00
|
|
|
match user {
|
|
|
|
|
Ok(Some(u)) => {
|
|
|
|
|
if u.verify(&auth.token, &auth.salt) {
|
|
|
|
|
SubsonicResponse::new_empty()
|
|
|
|
|
} else {
|
|
|
|
|
SubsonicResponse::new_error(subsonic::Error::WrongUsernameOrPassword(None))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(None) => SubsonicResponse::new_error(subsonic::Error::WrongUsernameOrPassword(None)),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
tracing::error!("Error getting user: {}", e);
|
|
|
|
|
SubsonicResponse::new_error(subsonic::Error::WrongUsernameOrPassword(None))
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-08 19:53:42 +00:00
|
|
|
}
|