ttl parsing error fix
This commit is contained in:
parent
b5efe1af10
commit
562475f242
3 changed files with 17 additions and 3 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -197,8 +197,7 @@ async fn get_index(
|
|||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PostQuery {
|
||||
#[serde(deserialize_with = "deserialize_option_duration")]
|
||||
ttl: Option<Duration>,
|
||||
ttl: Option<String>,
|
||||
}
|
||||
|
||||
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) => {
|
||||
|
|
Loading…
Reference in a new issue