rave/src/rest/ping.rs

29 lines
874 B
Rust
Raw Normal View History

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]
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
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
}