ttl overflow fix

This commit is contained in:
Paul Zinselmeyer 2023-10-20 10:00:23 +02:00
parent a8180ba55b
commit 5ac3a20b6c

View file

@ -231,14 +231,20 @@ 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 => u64::MAX,
false => now + ttl,
};
metadata.etag = Some(hex::encode(etag_hasher.finalize()));
metadata.size = Some(size);
metadata.content_type = match content_type {
Some(content_type) => Some(content_type.to_string()),
None => Some("application/octet-stream".to_string()),
};
metadata.expires_at = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs()
+ params.ttl.unwrap_or(24 * 3600);
metadata.expires_at = expires_at;
metadata.to_file(&metadata_path).await?;
app_state