mirror of
https://github.com/flibusta-apps/batch_downloader.git
synced 2025-12-06 14:25:36 +01:00
26 lines
736 B
Rust
26 lines
736 B
Rust
use chrono::{DateTime, Utc, Duration};
|
|
use minio_rsc::{client::ListObjectsArgs, datatype::Object};
|
|
|
|
use super::minio::get_minio;
|
|
|
|
|
|
pub async fn clean_files(bucket: String) -> Result<(), Box<dyn std::error::Error>> {
|
|
let minio_client = get_minio();
|
|
|
|
let objects = minio_client.list_objects(
|
|
&bucket,
|
|
ListObjectsArgs::default()
|
|
).await?;
|
|
|
|
let delete_before = Utc::now() - Duration::hours(3);
|
|
for Object { key, last_modified, .. } in objects.contents {
|
|
let last_modified_date: DateTime<Utc> = DateTime::parse_from_rfc3339(&last_modified)?.into();
|
|
|
|
if last_modified_date <= delete_before {
|
|
let _ = minio_client.remove_object(&bucket, key).await;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|