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",
|
"clap",
|
||||||
"confy",
|
"confy",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"exitcode",
|
||||||
"open",
|
"open",
|
||||||
"openidconnect",
|
"openidconnect",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
@ -822,6 +823,12 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "exitcode"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ff"
|
name = "ff"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
|
|
@ -35,6 +35,9 @@ pub enum Error {
|
||||||
|
|
||||||
#[error("invalid multipart")]
|
#[error("invalid multipart")]
|
||||||
InvalidMultipart,
|
InvalidMultipart,
|
||||||
|
|
||||||
|
#[error("invalid ttl")]
|
||||||
|
InvalidTtl,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoResponse for Error {
|
impl IntoResponse for Error {
|
||||||
|
@ -50,6 +53,7 @@ impl IntoResponse for Error {
|
||||||
Self::InvalidMultipart => {
|
Self::InvalidMultipart => {
|
||||||
(StatusCode::BAD_REQUEST, "invalid multipart data").into_response()
|
(StatusCode::BAD_REQUEST, "invalid multipart data").into_response()
|
||||||
}
|
}
|
||||||
|
Self::InvalidTtl => (StatusCode::BAD_REQUEST, "invalid ttl specified").into_response(),
|
||||||
_ => {
|
_ => {
|
||||||
error!("{:?}", self);
|
error!("{:?}", self);
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, "internal server error\n").into_response()
|
(StatusCode::INTERNAL_SERVER_ERROR, "internal server error\n").into_response()
|
||||||
|
|
|
@ -197,8 +197,7 @@ async fn get_index(
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct PostQuery {
|
pub struct PostQuery {
|
||||||
#[serde(deserialize_with = "deserialize_option_duration")]
|
ttl: Option<String>,
|
||||||
ttl: Option<Duration>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn post_item(
|
async fn post_item(
|
||||||
|
@ -228,7 +227,11 @@ async fn post_item(
|
||||||
let mut etag_hasher = Sha3_256::new();
|
let mut etag_hasher = Sha3_256::new();
|
||||||
let mut size: u64 = 0;
|
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 {
|
match data {
|
||||||
MultipartOrStream::Stream(mut stream) => {
|
MultipartOrStream::Stream(mut stream) => {
|
||||||
|
|
Loading…
Reference in a new issue