mirror of
https://github.com/flibusta-apps/batch_downloader.git
synced 2025-12-06 14:25:36 +01:00
Add deleting old archives
This commit is contained in:
26
src/services/files_cleaner.rs
Normal file
26
src/services/files_cleaner.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use chrono::{DateTime, Utc, Duration};
|
||||
use minio_rsc::{client::ListObjectsArgs, datatype::Object};
|
||||
|
||||
use super::minio::get_minio;
|
||||
use crate::config;
|
||||
|
||||
|
||||
pub async fn clean_files() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let minio_client = get_minio();
|
||||
|
||||
let objects = minio_client.list_objects(
|
||||
&config::CONFIG.minio_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(&config::CONFIG.minio_bucket, key).await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user