Fix: Extract Cloudflare ID from photo URL

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 21:07:29 +00:00
parent ddab91e81f
commit 2e57cff34f

View File

@@ -570,16 +570,40 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
return; 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 // Create photo records in the photos table
const photoRecords = photosArray.map((photo, index) => { 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 = { const record = {
entity_id: entityId, entity_id: entityId,
entity_type: entityType, entity_type: entityType,
cloudflare_image_id: photo.imageId || photo.cloudflare_image_id, cloudflare_image_id: cloudflareImageId,
cloudflare_image_url: photo.url || photo.cloudflare_image_url, cloudflare_image_url: cloudflareImageUrl,
title: photo.title, title: photo.title || null,
caption: photo.caption, caption: photo.caption || null,
date_taken: photo.date, date_taken: photo.date || null,
order_index: photo.order ?? index, order_index: photo.order ?? index,
submission_id: item.id, submission_id: item.id,
submitted_by: item.user_id, submitted_by: item.user_id,