mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 20:51:17 -05:00
Fix: Extract Cloudflare ID from photo URL
This commit is contained in:
@@ -570,16 +570,40 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((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,
|
||||
|
||||
Reference in New Issue
Block a user