From 2e57cff34f48f0b0b3cf106dd94d05db37c6f464 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:07:29 +0000 Subject: [PATCH] Fix: Extract Cloudflare ID from photo URL --- src/components/moderation/ModerationQueue.tsx | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 8542f492..d1973ffc 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -570,16 +570,40 @@ export const ModerationQueue = forwardRef((props, ref) => { return; } + // Helper function to extract Cloudflare image ID from URL + const extractImageId = (url: string): string | null => { + try { + // URL format: https://imagedelivery.net/{account_hash}/{image_id}/public + const match = url.match(/\/([a-f0-9-]{36})\/public/i); + return match ? match[1] : null; + } catch (error) { + console.error('🖼️ [PHOTO APPROVAL] Error extracting image ID:', error); + return null; + } + }; + // Create photo records in the photos table const photoRecords = photosArray.map((photo, index) => { + const cloudflareImageUrl = photo.cloudflare_image_url || photo.url; + const cloudflareImageId = photo.cloudflare_image_id || photo.imageId || extractImageId(cloudflareImageUrl); + + if (!cloudflareImageId || !cloudflareImageUrl) { + console.error('🖼️ [PHOTO APPROVAL] ERROR: Missing Cloudflare fields', { + photo, + cloudflareImageId, + cloudflareImageUrl + }); + throw new Error('Missing required Cloudflare image fields'); + } + const record = { entity_id: entityId, entity_type: entityType, - cloudflare_image_id: photo.imageId || photo.cloudflare_image_id, - cloudflare_image_url: photo.url || photo.cloudflare_image_url, - title: photo.title, - caption: photo.caption, - date_taken: photo.date, + cloudflare_image_id: cloudflareImageId, + cloudflare_image_url: cloudflareImageUrl, + title: photo.title || null, + caption: photo.caption || null, + date_taken: photo.date || null, order_index: photo.order ?? index, submission_id: item.id, submitted_by: item.user_id,