Fix deletion of photos for submissions

This commit is contained in:
gpt-engineer-app[bot]
2025-09-29 00:02:53 +00:00
parent 624de77992
commit c9cd4318d4

View File

@@ -288,6 +288,35 @@ export function ModerationQueue() {
setActionLoading(item.id); setActionLoading(item.id);
try { try {
// Step 1: Extract photo IDs from the submission content
const photoIds: string[] = [];
if (item.content?.photos && Array.isArray(item.content.photos)) {
for (const photo of item.content.photos) {
if (photo.imageId) {
photoIds.push(photo.imageId);
}
}
}
// Step 2: Delete photos from Cloudflare Images (if any)
if (photoIds.length > 0) {
const deletePromises = photoIds.map(async (imageId) => {
try {
await supabase.functions.invoke('upload-image', {
method: 'DELETE',
body: { imageId }
});
} catch (deleteError) {
console.warn(`Failed to delete photo ${imageId} from Cloudflare:`, deleteError);
// Continue with other deletions - don't fail the entire operation
}
});
// Execute all photo deletions in parallel
await Promise.allSettled(deletePromises);
}
// Step 3: Delete the submission from the database
const { error } = await supabase const { error } = await supabase
.from('content_submissions') .from('content_submissions')
.delete() .delete()
@@ -297,7 +326,7 @@ export function ModerationQueue() {
toast({ toast({
title: "Submission deleted", title: "Submission deleted",
description: "The submission has been permanently deleted", description: `The submission and ${photoIds.length > 0 ? `${photoIds.length} associated photo(s) have` : 'has'} been permanently deleted`,
}); });
// Remove item from the current view // Remove item from the current view