diff --git a/src/error.rs b/src/error.rs index b6e9822..a6a6d7a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -35,6 +35,9 @@ pub enum Error { #[error("invalid multipart")] InvalidMultipart, + + #[error("invalid ttl")] + InvalidTtl, } impl IntoResponse for Error { @@ -50,6 +53,7 @@ impl IntoResponse for Error { Self::InvalidMultipart => { (StatusCode::BAD_REQUEST, "invalid multipart data").into_response() } + Self::InvalidTtl => (StatusCode::BAD_REQUEST, "invalid ttl specified").into_response(), _ => { error!("{:?}", self); (StatusCode::INTERNAL_SERVER_ERROR, "internal server error\n").into_response() diff --git a/src/main.rs b/src/main.rs index 6de1def..60f1461 100644 --- a/src/main.rs +++ b/src/main.rs @@ -197,8 +197,7 @@ async fn get_index( #[derive(Deserialize)] pub struct PostQuery { - #[serde(deserialize_with = "deserialize_option_duration")] - ttl: Option, + ttl: Option, } async fn post_item( @@ -228,7 +227,11 @@ async fn post_item( let mut etag_hasher = Sha3_256::new(); let mut size: u64 = 0; - let mut ttl = params.ttl.unwrap_or(Duration::from_secs(24 * 3600)); + let mut ttl = params + .ttl + .map(|x| duration_str::parse(&x).map_err(|_| Error::InvalidTtl)) + .transpose()? + .unwrap_or(Duration::from_secs(24 * 3600)); match data { MultipartOrStream::Stream(mut stream) => {