multipart ttl
This commit is contained in:
parent
69d8bd1d8e
commit
0e4532828a
1 changed files with 12 additions and 3 deletions
15
src/main.rs
15
src/main.rs
|
@ -226,6 +226,8 @@ 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(24 * 3600);
|
||||||
|
|
||||||
match data {
|
match data {
|
||||||
MultipartOrStream::Stream(mut stream) => {
|
MultipartOrStream::Stream(mut stream) => {
|
||||||
while let Some(chunk) = stream.next().await {
|
while let Some(chunk) = stream.next().await {
|
||||||
|
@ -241,12 +243,13 @@ async fn post_item(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MultipartOrStream::Multipart(mut multipart) => {
|
MultipartOrStream::Multipart(mut multipart) => {
|
||||||
|
let mut file_read = false;
|
||||||
while let Some(mut field) = multipart
|
while let Some(mut field) = multipart
|
||||||
.next_field()
|
.next_field()
|
||||||
.await
|
.await
|
||||||
.map_err(|_| Error::InvalidMultipart)?
|
.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() {
|
while let Some(chunk) = field.chunk().await.unwrap_or_default() {
|
||||||
let mut buf = chunk.to_vec();
|
let mut buf = chunk.to_vec();
|
||||||
etag_hasher.update(&buf);
|
etag_hasher.update(&buf);
|
||||||
|
@ -260,7 +263,14 @@ async fn post_item(
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.unwrap_or("application/octet-stream".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?;
|
writer.flush().await?;
|
||||||
|
|
||||||
let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
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 {
|
let expires_at = match u64::MAX - ttl > now {
|
||||||
true => now + ttl,
|
true => now + ttl,
|
||||||
false => u64::MAX,
|
false => u64::MAX,
|
||||||
|
|
Loading…
Reference in a new issue