Fix old URL generation

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 01:06:50 +00:00
parent 9f52d423f0
commit f95eaf9eb7
5 changed files with 21 additions and 26 deletions

View File

@@ -40,7 +40,7 @@ interface RideData {
async function getPageData(pathname: string, fullUrl: string): Promise<PageData> {
const normalizedPath = pathname.replace(/\/+$/, '') || '/';
const DEFAULT_FALLBACK_IMAGE = 'https://imagedelivery.net/X-2-mmiWukWxvAQQ2_o-7Q/4af6a0c6-4450-497d-772f-08da62274100/original';
const DEFAULT_FALLBACK_IMAGE = 'https://cdn.thrillwiki.com/images/4af6a0c6-4450-497d-772f-08da62274100/original';
// Individual park page: /parks/{slug}
if (normalizedPath.startsWith('/parks/') && normalizedPath.split('/').length === 3) {
@@ -63,7 +63,7 @@ async function getPageData(pathname: string, fullUrl: string): Promise<PageData>
const park = data[0] as ParkData;
const imageUrl = park.banner_image_url ||
(park.banner_image_id
? `https://imagedelivery.net/${process.env.CLOUDFLARE_ACCOUNT_HASH}/${park.banner_image_id}/original`
? `https://cdn.thrillwiki.com/images/${park.banner_image_id}/original`
: (process.env.DEFAULT_OG_IMAGE || DEFAULT_FALLBACK_IMAGE));
return {
@@ -102,7 +102,7 @@ async function getPageData(pathname: string, fullUrl: string): Promise<PageData>
const ride = data[0] as RideData;
const imageUrl = ride.banner_image_url ||
(ride.banner_image_id
? `https://imagedelivery.net/${process.env.CLOUDFLARE_ACCOUNT_HASH}/${ride.banner_image_id}/original`
? `https://cdn.thrillwiki.com/images/${ride.banner_image_id}/original`
: (process.env.DEFAULT_OG_IMAGE || DEFAULT_FALLBACK_IMAGE));
return {
@@ -124,7 +124,7 @@ async function getPageData(pathname: string, fullUrl: string): Promise<PageData>
return {
title: 'Theme Parks - ThrillWiki',
description: 'Browse theme parks and amusement parks from around the world',
image: process.env.DEFAULT_OG_IMAGE || 'https://imagedelivery.net/X-2-mmiWukWxvAQQ2_o-7Q/4af6a0c6-4450-497d-772f-08da62274100/original',
image: process.env.DEFAULT_OG_IMAGE || 'https://cdn.thrillwiki.com/images/4af6a0c6-4450-497d-772f-08da62274100/original',
url: fullUrl,
type: 'website'
};
@@ -135,7 +135,7 @@ async function getPageData(pathname: string, fullUrl: string): Promise<PageData>
return {
title: 'Roller Coasters & Rides - ThrillWiki',
description: 'Explore roller coasters and theme park rides from around the world',
image: process.env.DEFAULT_OG_IMAGE || 'https://imagedelivery.net/X-2-mmiWukWxvAQQ2_o-7Q/4af6a0c6-4450-497d-772f-08da62274100/original',
image: process.env.DEFAULT_OG_IMAGE || 'https://cdn.thrillwiki.com/images/4af6a0c6-4450-497d-772f-08da62274100/original',
url: fullUrl,
type: 'website'
};
@@ -145,7 +145,7 @@ async function getPageData(pathname: string, fullUrl: string): Promise<PageData>
return {
title: 'ThrillWiki - Theme Park & Roller Coaster Database',
description: 'Explore theme parks and roller coasters worldwide with ThrillWiki',
image: process.env.DEFAULT_OG_IMAGE || 'https://imagedelivery.net/X-2-mmiWukWxvAQQ2_o-7Q/4af6a0c6-4450-497d-772f-08da62274100/original',
image: process.env.DEFAULT_OG_IMAGE || 'https://cdn.thrillwiki.com/images/4af6a0c6-4450-497d-772f-08da62274100/original',
url: fullUrl,
type: 'website'
};

View File

@@ -151,7 +151,7 @@ export function MarkdownEditor({
if (error) throw error;
// Return CloudFlare imagedelivery.net URL
// Return Cloudflare CDN URL
const imageUrl = getCloudflareImageUrl((data as { id: string }).id, 'public');
if (!imageUrl) throw new Error('Failed to generate image URL');

View File

@@ -8,17 +8,15 @@ const corsHeaders = {
};
const CLOUDFLARE_ACCOUNT_ID = Deno.env.get('CLOUDFLARE_ACCOUNT_ID');
const CLOUDFLARE_ACCOUNT_HASH = Deno.env.get('CLOUDFLARE_ACCOUNT_HASH');
const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN');
// Validate configuration at startup
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
console.error('[OAuth Profile] Missing Cloudflare configuration:', {
hasAccountId: !!CLOUDFLARE_ACCOUNT_ID,
hasAccountHash: !!CLOUDFLARE_ACCOUNT_HASH,
hasApiToken: !!CLOUDFLARE_API_TOKEN,
});
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_ACCOUNT_HASH, and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
}
interface GoogleUserMetadata {
@@ -204,11 +202,10 @@ Deno.serve(async (req) => {
// Download and upload avatar to Cloudflare
if (avatarUrl) {
// Validate secrets before attempting upload
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload');
console.warn('[OAuth Profile] Missing:', {
accountId: !CLOUDFLARE_ACCOUNT_ID,
accountHash: !CLOUDFLARE_ACCOUNT_HASH,
apiToken: !CLOUDFLARE_API_TOKEN,
});
} else {
@@ -287,7 +284,6 @@ Deno.serve(async (req) => {
error: error.message,
provider: provider,
accountId: CLOUDFLARE_ACCOUNT_ID,
accountHash: CLOUDFLARE_ACCOUNT_HASH,
hasToken: !!CLOUDFLARE_API_TOKEN,
avatarUrl,
});

View File

@@ -425,14 +425,14 @@ Deno.serve(async (req) => {
if (level >= 3) {
companyData.website_url = `https://test-${compType}-${i + 1}.example.com`;
companyData.logo_url = `https://imagedelivery.net/test/${compType}-${i + 1}/logo`;
companyData.logo_url = `https://cdn.thrillwiki.com/images/test-${compType}-${i + 1}-logo/logo`;
}
if (level >= 4) {
companyData.card_image_id = `test-${compType}-card-${i + 1}`;
companyData.card_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/card`;
companyData.card_image_url = `https://cdn.thrillwiki.com/images/test-${compType}-card-${i + 1}/card`;
companyData.banner_image_id = `test-${compType}-banner-${i + 1}`;
companyData.banner_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/banner`;
companyData.banner_image_url = `https://cdn.thrillwiki.com/images/test-${compType}-banner-${i + 1}/banner`;
}
const { itemId } = await createSubmission(user.id, compType, companyData);
@@ -505,7 +505,7 @@ Deno.serve(async (req) => {
}
parkData.email = `info@test-park-${i + 1}.example.com`;
parkData.card_image_id = `test-park-card-${i + 1}`;
parkData.card_image_url = `https://imagedelivery.net/test/park-${i + 1}/card`;
parkData.card_image_url = `https://cdn.thrillwiki.com/images/test-park-card-${i + 1}/card`;
}
if (level >= 4) {
@@ -522,7 +522,7 @@ Deno.serve(async (req) => {
parkData.status = 'closed';
}
parkData.banner_image_id = `test-park-banner-${i + 1}`;
parkData.banner_image_url = `https://imagedelivery.net/test/park-${i + 1}/banner`;
parkData.banner_image_url = `https://cdn.thrillwiki.com/images/test-park-banner-${i + 1}/banner`;
}
const options = {
@@ -612,7 +612,7 @@ Deno.serve(async (req) => {
rideData.seating_type = randomItem(['sit_down', 'inverted', 'flying', 'stand_up']);
}
rideData.card_image_id = `test-ride-card-${i + 1}`;
rideData.card_image_url = `https://imagedelivery.net/test/ride-${i + 1}/card`;
rideData.card_image_url = `https://cdn.thrillwiki.com/images/test-ride-card-${i + 1}/card`;
}
if (level >= 4) {
@@ -624,7 +624,7 @@ Deno.serve(async (req) => {
rideData.drop_height_meters = randomInt(10, 80);
rideData.max_g_force = (Math.random() * 4 + 2).toFixed(1);
rideData.banner_image_id = `test-ride-banner-${i + 1}`;
rideData.banner_image_url = `https://imagedelivery.net/test/ride-${i + 1}/banner`;
rideData.banner_image_url = `https://cdn.thrillwiki.com/images/test-ride-banner-${i + 1}/banner`;
}
const options = {
@@ -713,12 +713,12 @@ Deno.serve(async (req) => {
if (level >= 2) {
modelData.card_image_id = `test-model-card-${i + 1}`;
modelData.card_image_url = `https://imagedelivery.net/test/model-${i + 1}/card`;
modelData.card_image_url = `https://cdn.thrillwiki.com/images/test-model-card-${i + 1}/card`;
}
if (level >= 3) {
modelData.banner_image_id = `test-model-banner-${i + 1}`;
modelData.banner_image_url = `https://imagedelivery.net/test/model-${i + 1}/banner`;
modelData.banner_image_url = `https://cdn.thrillwiki.com/images/test-model-banner-${i + 1}/banner`;
}
const options = {
@@ -806,7 +806,7 @@ Deno.serve(async (req) => {
await supabase.from('photo_submission_items').insert({
photo_submission_id: photoSubmissionId,
cloudflare_image_id: imageId,
cloudflare_image_url: `https://imagedelivery.net/test/${imageId}/public`,
cloudflare_image_url: `https://cdn.thrillwiki.com/images/${imageId}/public`,
caption: Math.random() > 0.3 ? `Test photo ${p + 1} - Great view of the ${entityType}` : null,
title: Math.random() > 0.7 ? `Photo ${p + 1}` : null,
filename: `photo-${p + 1}.jpg`,

View File

@@ -99,9 +99,8 @@ serve(async (req) => {
try {
const CLOUDFLARE_ACCOUNT_ID = Deno.env.get('CLOUDFLARE_ACCOUNT_ID')
const CLOUDFLARE_IMAGES_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN')
const CLOUDFLARE_ACCOUNT_HASH = Deno.env.get('CLOUDFLARE_ACCOUNT_HASH')
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_IMAGES_API_TOKEN || !CLOUDFLARE_ACCOUNT_HASH) {
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_IMAGES_API_TOKEN) {
throw new Error('Missing Cloudflare credentials')
}