Skip to content
Clone
58775d4
32 lines 936 B Rust
use std::future::Future;
use std::pin::Pin;
use actix_web::dev::Payload;
use actix_web::{FromRequest, HttpRequest};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::errors::ApiError;
#[derive(Debug, Clone, Deserialize, IntoParams)]
pub struct PullPath {
pub space_name: String,
pub repo_name: String,
/// PR 编号(`12`)或 UUID。
pub pull_ref: String,
}
impl FromRequest for PullPath {
type Error = ApiError;
type Future = Pin<Box<dyn Future<Output = Result<Self, Self::Error>>>>;
fn from_request(request: &HttpRequest, _payload: &mut Payload) -> Self::Future {
let request = request.clone();
Box::pin(async move {
actix_web::web::Path::<PullPath>::from_request(&request, &mut Payload::None)
.await
.map(|value| value.into_inner())
.map_err(|_| ApiError::bad_request("invalid request path"))
})
}
}