From 4ddc10b8eb07ab97cf390a0ac63ee5875c5c32d6 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 17:23:38 +0000 Subject: [PATCH] Refactor: Improve Cloudflare direct upload --- src/components/upload/PhotoUpload.tsx | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/components/upload/PhotoUpload.tsx b/src/components/upload/PhotoUpload.tsx index 76873bcb..d6348a7c 100644 --- a/src/components/upload/PhotoUpload.tsx +++ b/src/components/upload/PhotoUpload.tsx @@ -114,26 +114,18 @@ export function PhotoUpload({ let attempts = 0; while (attempts < maxAttempts) { - const statusUrl = `https://ydvtmnrszybqnbcqbdcy.supabase.co/functions/v1/upload-image?id=${id}`; - const statusResponse = await fetch(statusUrl, { + const { data: statusData, error: statusError } = await supabase.functions.invoke('upload-image', { method: 'GET', - headers: { - 'Authorization': `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InlkdnRtbnJzenlicW5iY3FiZGN5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTgzMjYzNTYsImV4cCI6MjA3MzkwMjM1Nn0.DM3oyapd_omP5ZzIlrT0H9qBsiQBxBRgw2tYuqgXKX4`, - 'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InlkdnRtbnJzenlicW5iY3FiZGN5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTgzMjYzNTYsImV4cCI6MjA3MzkwMjM1Nn0.DM3oyapd_omP5ZzIlrT0H9qBsiQBxBRgw2tYuqgXKX4' - } + body: { id } }); - if (statusResponse.ok) { - const statusData = await statusResponse.json(); - - if (statusData?.success && !statusData.draft && statusData.urls) { - return { - id: statusData.id, - url: statusData.urls.original, - filename: file.name, - thumbnailUrl: statusData.urls.thumbnail - }; - } + if (!statusError && statusData?.success && statusData.uploaded && statusData.urls) { + return { + id: statusData.id, + url: statusData.urls.original, + filename: file.name, + thumbnailUrl: statusData.urls.thumbnail + }; } // Wait 1 second before checking again