mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 06:51:13 -05:00
Fix photo deletion logic
This commit is contained in:
@@ -419,49 +419,42 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
|
|
||||||
if (item.content?.photos && Array.isArray(item.content.photos)) {
|
if (item.content?.photos && Array.isArray(item.content.photos)) {
|
||||||
for (const photo of 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)
|
// Check if this looks like a Cloudflare image ID (not a blob URL)
|
||||||
if (photo.url.startsWith('blob:')) {
|
if (photo.url.startsWith('blob:')) {
|
||||||
// This is a blob URL - we can't extract a valid Cloudflare image ID
|
// 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);
|
console.warn('Skipping blob URL (cannot extract Cloudflare image ID):', photo.url);
|
||||||
skippedPhotos.push(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 {
|
} else {
|
||||||
// Try to extract image ID from various URL formats
|
// Extract from Cloudflare image delivery URL format
|
||||||
let imageId = '';
|
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) {
|
||||||
// UUID pattern: 8-4-4-4-12 characters
|
imageId = cloudflareMatch[1];
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user