mirror of
https://github.com/flibusta-apps/batch_downloader.git
synced 2025-12-06 06:15:37 +01:00
Add pre-commit config
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
use chrono::{DateTime, Utc, Duration};
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
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 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();
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user