mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:31:11 -05:00
Fix deletion of photos for submissions
This commit is contained in:
@@ -288,6 +288,35 @@ export function ModerationQueue() {
|
||||
|
||||
setActionLoading(item.id);
|
||||
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
|
||||
.from('content_submissions')
|
||||
.delete()
|
||||
@@ -297,7 +326,7 @@ export function ModerationQueue() {
|
||||
|
||||
toast({
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user