diff --git a/.env b/.env index 17bdd4ea5..283ffba46 100644 --- a/.env +++ b/.env @@ -23,6 +23,7 @@ S3_SECRET=none S3_URL=none S3_REGION=none S3_BUCKET_NAME=none +S3_PROVIDER=none # 1 hour LOCAL_INDEX_INTERVAL=3600 diff --git a/src/file_hosting/backblaze.rs b/src/file_hosting/backblaze.rs index ee9f7d7be..32899a750 100644 --- a/src/file_hosting/backblaze.rs +++ b/src/file_hosting/backblaze.rs @@ -76,7 +76,7 @@ impl FileHost for BackblazeHost { } } -#[cfg(test)] +/*#[cfg(test)] mod tests { use super::*; use authorization::*; @@ -132,4 +132,4 @@ mod tests { .await .unwrap(); } -} +}*/ diff --git a/src/file_hosting/s3_host.rs b/src/file_hosting/s3_host.rs index 427482c50..1596c8975 100644 --- a/src/file_hosting/s3_host.rs +++ b/src/file_hosting/s3_host.rs @@ -49,6 +49,33 @@ impl FileHost for S3Host { ) .await?; + let provider = &*dotenv::var("S3_PROVIDER").unwrap(); + + if provider == "do" { + reqwest::Client::new() + .delete(&*format!( + "https://api.digitalocean.com/v2/cdn/endpoints/{}/cache", + self.bucket.name + )) + .header(reqwest::header::CONTENT_TYPE, "application/json") + .header( + reqwest::header::AUTHORIZATION, + self.bucket + .credentials + .secret_key + .clone() + .unwrap_or_else(|| "".to_string()), + ) + .body( + serde_json::json!({ + "files": vec![file_name], + }) + .to_string(), + ) + .send() + .await?; + } + Ok(UploadFileData { file_id: file_name.to_string(), file_name: file_name.to_string(), diff --git a/src/main.rs b/src/main.rs index b212a711d..53918c7e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -334,6 +334,7 @@ fn check_env_vars() -> bool { failed |= check_var::("S3_URL"); failed |= check_var::("S3_REGION"); failed |= check_var::("S3_BUCKET_NAME"); + failed |= check_var::("S3_PROVIDER"); } else if storage_backend.as_deref() == Some("local") { failed |= check_var::("MOCK_FILE_PATH"); } else if let Some(backend) = storage_backend {