mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 01:51:12 -05:00
Fix: Use account hash for Cloudflare avatars
This commit is contained in:
@@ -6,16 +6,16 @@ const corsHeaders = {
|
|||||||
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
||||||
};
|
};
|
||||||
|
|
||||||
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');
|
const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN');
|
||||||
|
|
||||||
// Validate configuration at startup
|
// Validate configuration at startup
|
||||||
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
|
if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
|
||||||
console.error('[OAuth Profile] Missing Cloudflare configuration:', {
|
console.error('[OAuth Profile] Missing Cloudflare configuration:', {
|
||||||
hasAccountId: !!CLOUDFLARE_ACCOUNT_ID,
|
hasAccountHash: !!CLOUDFLARE_ACCOUNT_HASH,
|
||||||
hasApiToken: !!CLOUDFLARE_API_TOKEN,
|
hasApiToken: !!CLOUDFLARE_API_TOKEN,
|
||||||
});
|
});
|
||||||
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
|
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_HASH and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GoogleUserMetadata {
|
interface GoogleUserMetadata {
|
||||||
@@ -116,10 +116,10 @@ Deno.serve(async (req) => {
|
|||||||
// Download and upload avatar to Cloudflare
|
// Download and upload avatar to Cloudflare
|
||||||
if (avatarUrl) {
|
if (avatarUrl) {
|
||||||
// Validate secrets before attempting upload
|
// Validate secrets before attempting upload
|
||||||
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
|
if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
|
||||||
console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload');
|
console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload');
|
||||||
console.warn('[OAuth Profile] Missing:', {
|
console.warn('[OAuth Profile] Missing:', {
|
||||||
accountId: !CLOUDFLARE_ACCOUNT_ID,
|
accountHash: !CLOUDFLARE_ACCOUNT_HASH,
|
||||||
apiToken: !CLOUDFLARE_API_TOKEN,
|
apiToken: !CLOUDFLARE_API_TOKEN,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -153,7 +153,7 @@ Deno.serve(async (req) => {
|
|||||||
|
|
||||||
// Get upload URL from Cloudflare
|
// Get upload URL from Cloudflare
|
||||||
const uploadUrlResponse = await fetch(
|
const uploadUrlResponse = await fetch(
|
||||||
`https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/images/v2/direct_upload`,
|
`https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_HASH}/images/v2/direct_upload`,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -188,7 +188,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_ID}/${cloudflareImageId}/avatar`;
|
cloudflareImageUrl = `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${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');
|
||||||
@@ -196,7 +196,7 @@ Deno.serve(async (req) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[OAuth Profile] Avatar upload failed:', {
|
console.error('[OAuth Profile] Avatar upload failed:', {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
accountId: CLOUDFLARE_ACCOUNT_ID,
|
accountHash: CLOUDFLARE_ACCOUNT_HASH,
|
||||||
hasToken: !!CLOUDFLARE_API_TOKEN,
|
hasToken: !!CLOUDFLARE_API_TOKEN,
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user