43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use actix_web::{HttpRequest, HttpResponse, web};
|
|
|
|
use crate::state::AppState;
|
|
|
|
use super::helpers::{authenticate, get_query_param, parse_subsonic_id};
|
|
use super::response;
|
|
|
|
/// GET /rest/scrobble[.view]
|
|
pub async fn scrobble(req: HttpRequest, state: web::Data<AppState>) -> HttpResponse {
|
|
let (params, user) = match authenticate(&req, &state).await {
|
|
Ok(v) => v,
|
|
Err(resp) => return resp,
|
|
};
|
|
|
|
let id_str = match get_query_param(&req, "id") {
|
|
Some(id) => id,
|
|
None => {
|
|
return response::error(
|
|
¶ms.format,
|
|
response::ERROR_MISSING_PARAM,
|
|
"missing required parameter: id",
|
|
);
|
|
}
|
|
};
|
|
|
|
let (prefix, entity_id) = match parse_subsonic_id(&id_str) {
|
|
Some(v) => v,
|
|
None => {
|
|
return response::error(¶ms.format, response::ERROR_NOT_FOUND, "invalid id");
|
|
}
|
|
};
|
|
|
|
// Log the scrobble for now; full play tracking can be added later
|
|
tracing::info!(
|
|
user = %user.username,
|
|
id_type = prefix,
|
|
id = entity_id,
|
|
"subsonic scrobble"
|
|
);
|
|
|
|
response::ok(¶ms.format, serde_json::json!({}))
|
|
}
|