mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 08:51:13 -05:00
Refactor: Update CDN image delivery URLs
This commit is contained in:
@@ -144,8 +144,7 @@ export function UppyPhotoUpload({
|
|||||||
if (statusResponse.ok) {
|
if (statusResponse.ok) {
|
||||||
const status: UploadSuccessResponse = await statusResponse.json();
|
const status: UploadSuccessResponse = await statusResponse.json();
|
||||||
if (status.uploaded && status.urls) {
|
if (status.uploaded && status.urls) {
|
||||||
const CLOUDFLARE_ACCOUNT_HASH = import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH;
|
return `https://cdn.thrillwiki.com/images/${cloudflareId}/public`;
|
||||||
return `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${cloudflareId}/public`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,17 +12,16 @@ export type CloudflareVariant =
|
|||||||
| 'logo'
|
| 'logo'
|
||||||
| 'public';
|
| 'public';
|
||||||
|
|
||||||
const CLOUDFLARE_ACCOUNT_HASH = import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a Cloudflare image URL with specified variant
|
* Build a Cloudflare image URL with specified variant
|
||||||
|
* Uses CDN proxy for branded URLs
|
||||||
*/
|
*/
|
||||||
export function getCloudflareImageUrl(
|
export function getCloudflareImageUrl(
|
||||||
imageId: string | undefined,
|
imageId: string | undefined,
|
||||||
variant: CloudflareVariant = 'public'
|
variant: CloudflareVariant = 'public'
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
if (!imageId) return undefined;
|
if (!imageId) return undefined;
|
||||||
return `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${imageId}/${variant}`;
|
return `https://cdn.thrillwiki.com/images/${imageId}/${variant}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,9 +52,14 @@ export function getBannerUrls(imageId: string | undefined) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract Cloudflare image ID from various URL formats
|
* Extract Cloudflare image ID from various URL formats
|
||||||
|
* Supports both old imagedelivery.net and new CDN URLs
|
||||||
*/
|
*/
|
||||||
export function extractCloudflareImageId(url: string): string | null {
|
export function extractCloudflareImageId(url: string): string | null {
|
||||||
// Match imagedelivery.net URLs
|
// Match old imagedelivery.net URLs
|
||||||
const match = url.match(/imagedelivery\.net\/[^\/]+\/([a-f0-9-]+)\//i);
|
const deliveryMatch = url.match(/imagedelivery\.net\/[^\/]+\/([a-f0-9-]+)\//i);
|
||||||
return match ? match[1] : null;
|
if (deliveryMatch) return deliveryMatch[1];
|
||||||
|
|
||||||
|
// Match new cdn.thrillwiki.com URLs
|
||||||
|
const cdnMatch = url.match(/cdn\.thrillwiki\.com\/images\/([a-f0-9-]+)\//i);
|
||||||
|
return cdnMatch ? cdnMatch[1] : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,11 +88,9 @@ export async function uploadPendingImages(images: UploadedImage[]): Promise<Uplo
|
|||||||
// Clean up object URL
|
// Clean up object URL
|
||||||
URL.revokeObjectURL(image.url);
|
URL.revokeObjectURL(image.url);
|
||||||
|
|
||||||
const CLOUDFLARE_ACCOUNT_HASH = import.meta.env.VITE_CLOUDFLARE_ACCOUNT_HASH;
|
|
||||||
|
|
||||||
// Step 3: Return uploaded image metadata with wasNewlyUploaded flag
|
// Step 3: Return uploaded image metadata with wasNewlyUploaded flag
|
||||||
return {
|
return {
|
||||||
url: `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${result.result.id}/public`,
|
url: `https://cdn.thrillwiki.com/images/${result.result.id}/public`,
|
||||||
cloudflare_id: result.result.id,
|
cloudflare_id: result.result.id,
|
||||||
caption: image.caption,
|
caption: image.caption,
|
||||||
isLocal: false,
|
isLocal: false,
|
||||||
|
|||||||
@@ -105,11 +105,13 @@ export function normalizePhotoSubmissionItems(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate photo URL is from Cloudflare Images
|
* Validate photo URL is from Cloudflare Images
|
||||||
|
* Supports both old imagedelivery.net and new CDN URLs
|
||||||
*/
|
*/
|
||||||
export function isValidCloudflareUrl(url: string): boolean {
|
export function isValidCloudflareUrl(url: string): boolean {
|
||||||
try {
|
try {
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
return urlObj.hostname.includes('imagedelivery.net');
|
return urlObj.hostname.includes('imagedelivery.net') ||
|
||||||
|
urlObj.hostname === 'cdn.thrillwiki.com';
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { supabase } from '@/integrations/supabase/client';
|
import { supabase } from '@/integrations/supabase/client';
|
||||||
import { getErrorMessage } from './errorHandler';
|
import { getErrorMessage } from './errorHandler';
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
|
import { extractCloudflareImageId } from './cloudflareImageUtils';
|
||||||
|
|
||||||
// Core submission item interface with dependencies
|
// Core submission item interface with dependencies
|
||||||
// Type safety for item_data will be added in Phase 5 after fixing components
|
// Type safety for item_data will be added in Phase 5 after fixing components
|
||||||
@@ -735,11 +736,16 @@ async function approvePhotos(data: any, dependencyMap: Map<string, string>, user
|
|||||||
// Insert photos into the photos table
|
// Insert photos into the photos table
|
||||||
const photosToInsert = resolvedData.photos.map((photo: any, index: number) => {
|
const photosToInsert = resolvedData.photos.map((photo: any, index: number) => {
|
||||||
// Extract CloudFlare image ID from URL if not provided
|
// Extract CloudFlare image ID from URL if not provided
|
||||||
|
// Supports both old imagedelivery.net and new cdn.thrillwiki.com URLs
|
||||||
let cloudflareImageId = photo.cloudflare_image_id;
|
let cloudflareImageId = photo.cloudflare_image_id;
|
||||||
if (!cloudflareImageId && photo.url) {
|
if (!cloudflareImageId && photo.url) {
|
||||||
// URL format: https://imagedelivery.net/{account_hash}/{image_id}/{variant}
|
cloudflareImageId = extractCloudflareImageId(photo.url);
|
||||||
const urlParts = photo.url.split('/');
|
|
||||||
cloudflareImageId = urlParts[urlParts.length - 2];
|
// Fallback: parse from URL structure
|
||||||
|
if (!cloudflareImageId) {
|
||||||
|
const urlParts = photo.url.split('/');
|
||||||
|
cloudflareImageId = urlParts[urlParts.length - 2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ Deno.serve(async (req) => {
|
|||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
cloudflareImageId = result.result.id;
|
cloudflareImageId = result.result.id;
|
||||||
cloudflareImageUrl = `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${cloudflareImageId}/avatar`;
|
cloudflareImageUrl = `https://cdn.thrillwiki.com/images/${cloudflareImageId}/avatar`;
|
||||||
console.log('[OAuth Profile] Uploaded to Cloudflare:', { cloudflareImageId, cloudflareImageUrl });
|
console.log('[OAuth Profile] Uploaded to Cloudflare:', { cloudflareImageId, cloudflareImageUrl });
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Cloudflare upload failed');
|
throw new Error('Cloudflare upload failed');
|
||||||
|
|||||||
@@ -587,8 +587,8 @@ serve(async (req) => {
|
|||||||
const result = imageResult.result
|
const result = imageResult.result
|
||||||
const duration = endRequest(tracking);
|
const duration = endRequest(tracking);
|
||||||
|
|
||||||
// Construct proper imagedelivery.net URLs using account hash and image ID
|
// Construct CDN URLs for display
|
||||||
const baseUrl = `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${result.id}`
|
const baseUrl = `https://cdn.thrillwiki.com/images/${result.id}`
|
||||||
|
|
||||||
edgeLogger.info('Image status retrieved', { action: 'get_image_status', requestId: tracking.requestId, duration });
|
edgeLogger.info('Image status retrieved', { action: 'get_image_status', requestId: tracking.requestId, duration });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user