mirror of
https://tangled.org/tranquil.farm/tranquil-pds
synced 2026-08-01 23:16:05 +00:00
api: add xrpc query extractor
Lewis: May this revision serve well! <lu5a@proton.me>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user