api: add xrpc query extractor

Lewis: May this revision serve well! <lu5a@proton.me>
This commit is contained in:
Lewis
2026-07-25 08:27:39 +03:00
committed by Tangled
parent e931268f7e
commit 2bfea64ffc
2 changed files with 19 additions and 0 deletions
+1
View File
@@ -2,6 +2,7 @@ pub mod error;
pub mod invite;
pub mod proxy;
pub mod proxy_client;
pub mod query;
pub mod responses;
pub mod validation;
+18
View File
@@ -0,0 +1,18 @@
use axum::extract::FromRequestParts;
use axum::http::request::Parts;
use serde::de::DeserializeOwned;
use super::error::ApiError;
pub struct XrpcQuery<T>(pub T);
impl<T: DeserializeOwned, S: Send + Sync> FromRequestParts<S> for XrpcQuery<T> {
type Rejection = ApiError;
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
let raw = parts.uri.query().unwrap_or_default();
serde_urlencoded::from_str(raw)
.map(Self)
.map_err(|e| ApiError::InvalidRequest(e.to_string()))
}
}