diff --git a/src/main.rs b/src/main.rs index e05a7c1..3028cc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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