multipart ttl

This commit is contained in:
Paul Zinselmeyer 2023-10-20 14:18:23 +02:00
parent 69d8bd1d8e
commit 0e4532828a

View file

@ -226,6 +226,8 @@ async fn post_item(
let mut etag_hasher = Sha3_256::new();
let mut size: u64 = 0;
let mut ttl = params.ttl.unwrap_or(24 * 3600);
match data {
MultipartOrStream::Stream(mut stream) => {
while let Some(chunk) = stream.next().await {
@ -241,12 +243,13 @@ async fn post_item(
};
}
MultipartOrStream::Multipart(mut multipart) => {
let mut file_read = false;
while let Some(mut field) = multipart
.next_field()
.await
.map_err(|_| Error::InvalidMultipart)?
{
if field.name().unwrap_or_default() == "file" {
if field.name().unwrap_or_default() == "file" && !file_read {
while let Some(chunk) = field.chunk().await.unwrap_or_default() {
let mut buf = chunk.to_vec();
etag_hasher.update(&buf);
@ -260,7 +263,14 @@ async fn post_item(
.map(|x| x.to_string())
.unwrap_or("application/octet-stream".to_string()),
);
break;
file_read = true;
}
if field.name().unwrap_or_default() == "ttl" {
if let Some(mp_ttl) =
field.text().await.ok().and_then(|x| x.parse::<u64>().ok())
{
ttl = mp_ttl;
}
}
}
}
@ -268,7 +278,6 @@ async fn post_item(
writer.flush().await?;
let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
let ttl = params.ttl.unwrap_or(24 * 3600);
let expires_at = match u64::MAX - ttl > now {
true => now + ttl,
false => u64::MAX,