Clean up orphan images

This commit is contained in:
jude committed 2026-10-12 21:39:34 +01:00
1 parent 8763a8e74a
commit c3bb015d2f
11 files changed
+496 -2

No files matched your search

+14
View File
@@ -57,6 +57,20 @@ impl ImageUploads {
}
impl ImageUploadService {
// Cleanup uses the same storage configuration without loading the moderation model.
pub(crate) fn for_cleanup() -> Result<Option<Self>, Box<dyn std::error::Error + Send + Sync>> {
let values =
["S3_BUCKET", "S3_REGION", "S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY", "S3_PUBLIC_URL"]
.map(|name| env::var(name).unwrap_or_default());
if values.iter().all(|value| value.trim().is_empty()) {
return Ok(None);
}
if values.iter().any(|value| value.trim().is_empty()) {
return Err("Image cleanup requires all S3 upload settings".into());
}
Self::new(&values, false).map(Some).map_err(|error| error.to_string().into())
}
fn new(values: &[String; 5], check_nsfw: bool) -> Result<Self, Box<dyn std::error::Error>> {
let url = reqwest::Url::parse(&values[4])?;
let public_url = url.as_str().trim_end_matches('/').to_string();
+1 -1
View File
@@ -4,7 +4,7 @@ mod macros;
mod catchers;
mod fairings;
mod guards;
mod image_uploads;
pub(crate) mod image_uploads;
mod ip_blocking;
mod routes;