diff --git a/Cargo.lock b/Cargo.lock index b11b80a..eb3730e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,6 +322,7 @@ dependencies = [ "clap", "confy", "dirs", + "exitcode", "open", "openidconnect", "reqwest", @@ -822,6 +823,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "exitcode" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193" + [[package]] name = "ff" version = "0.13.0" diff --git a/server/src/error.rs b/server/src/error.rs index b6e9822..a6a6d7a 100644 --- a/server/src/error.rs +++ b/server/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/server/src/main.rs b/server/src/main.rs index 6de1def..60f1461 100644 --- a/server/src/main.rs +++ b/server/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) => {