ttl overflow fix
This commit is contained in:
parent
a8180ba55b
commit
5ac3a20b6c
1 changed files with 8 additions and 2 deletions
10
src/main.rs
10
src/main.rs
|
@ -231,14 +231,20 @@ async fn post_item(
|
||||||
|
|
||||||
writer.flush().await?;
|
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 => u64::MAX,
|
||||||
|
false => now + ttl,
|
||||||
|
};
|
||||||
|
|
||||||
metadata.etag = Some(hex::encode(etag_hasher.finalize()));
|
metadata.etag = Some(hex::encode(etag_hasher.finalize()));
|
||||||
metadata.size = Some(size);
|
metadata.size = Some(size);
|
||||||
metadata.content_type = match content_type {
|
metadata.content_type = match content_type {
|
||||||
Some(content_type) => Some(content_type.to_string()),
|
Some(content_type) => Some(content_type.to_string()),
|
||||||
None => Some("application/octet-stream".to_string()),
|
None => Some("application/octet-stream".to_string()),
|
||||||
};
|
};
|
||||||
metadata.expires_at = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs()
|
metadata.expires_at = expires_at;
|
||||||
+ params.ttl.unwrap_or(24 * 3600);
|
|
||||||
metadata.to_file(&metadata_path).await?;
|
metadata.to_file(&metadata_path).await?;
|
||||||
|
|
||||||
app_state
|
app_state
|
||||||
|
|
Loading…
Reference in a new issue