ttl parsing error fix
This commit is contained in:
parent
9daacaf406
commit
50c275a4ee
2 changed files with 10 additions and 3 deletions
|
@ -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