diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index f9f88873..cb24f4be 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -419,49 +419,42 @@ export const ModerationQueue = forwardRef((props, ref) => { if (item.content?.photos && Array.isArray(item.content.photos)) { for (const photo of item.content.photos) { - if (photo.url) { + let imageId = ''; + + // First try to use the stored imageId directly + if (photo.imageId) { + imageId = photo.imageId; + console.log('Using stored image ID:', imageId); + } else if (photo.url) { // Check if this looks like a Cloudflare image ID (not a blob URL) if (photo.url.startsWith('blob:')) { // This is a blob URL - we can't extract a valid Cloudflare image ID console.warn('Skipping blob URL (cannot extract Cloudflare image ID):', photo.url); skippedPhotos.push(photo.url); + continue; + } + + // Fallback: Try to extract from URL for backward compatibility + const uuidRegex = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i; + + if (uuidRegex.test(photo.url)) { + imageId = photo.url; } else { - // Try to extract image ID from various URL formats - let imageId = ''; - - // UUID pattern: 8-4-4-4-12 characters - const uuidRegex = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i; - - // If it's already just an ID - if (uuidRegex.test(photo.url)) { - imageId = photo.url; - } else { - // Extract from Cloudflare image delivery URL format: - // https://imagedelivery.net/X-2-mmiWukWxvAQQ2_o-7Q/IMAGE_ID/public - const cloudflareMatch = photo.url.match(/imagedelivery\.net\/[^\/]+\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/i); - if (cloudflareMatch) { - imageId = cloudflareMatch[1]; - } else { - // Fallback: Extract from URL path - const urlParts = photo.url.split('/'); - for (const part of urlParts) { - if (uuidRegex.test(part)) { - imageId = part; - break; - } - } - } - } - - if (imageId) { - photoIds.push(imageId); - validImageIds.push(imageId); - console.log('Successfully extracted image ID:', imageId, 'from URL:', photo.url); - } else { - console.warn('Could not extract valid image ID from URL:', photo.url); - skippedPhotos.push(photo.url); + // Extract from Cloudflare image delivery URL format + const cloudflareMatch = photo.url.match(/imagedelivery\.net\/[^\/]+\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/i); + if (cloudflareMatch) { + imageId = cloudflareMatch[1]; } } + console.log('Extracted image ID from URL:', imageId, 'from URL:', photo.url); + } + + if (imageId) { + photoIds.push(imageId); + validImageIds.push(imageId); + } else { + console.warn('Could not get valid image ID from photo:', photo); + skippedPhotos.push(photo.url || 'unknown'); } } }