mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 10:31:12 -05:00
Refactor: Improve Cloudflare direct upload
This commit is contained in:
@@ -114,19 +114,12 @@ export function PhotoUpload({
|
|||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
|
|
||||||
while (attempts < maxAttempts) {
|
while (attempts < maxAttempts) {
|
||||||
const statusUrl = `https://ydvtmnrszybqnbcqbdcy.supabase.co/functions/v1/upload-image?id=${id}`;
|
const { data: statusData, error: statusError } = await supabase.functions.invoke('upload-image', {
|
||||||
const statusResponse = await fetch(statusUrl, {
|
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
body: { id }
|
||||||
'Authorization': `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InlkdnRtbnJzenlicW5iY3FiZGN5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTgzMjYzNTYsImV4cCI6MjA3MzkwMjM1Nn0.DM3oyapd_omP5ZzIlrT0H9qBsiQBxBRgw2tYuqgXKX4`,
|
|
||||||
'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InlkdnRtbnJzenlicW5iY3FiZGN5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTgzMjYzNTYsImV4cCI6MjA3MzkwMjM1Nn0.DM3oyapd_omP5ZzIlrT0H9qBsiQBxBRgw2tYuqgXKX4'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (statusResponse.ok) {
|
if (!statusError && statusData?.success && statusData.uploaded && statusData.urls) {
|
||||||
const statusData = await statusResponse.json();
|
|
||||||
|
|
||||||
if (statusData?.success && !statusData.draft && statusData.urls) {
|
|
||||||
return {
|
return {
|
||||||
id: statusData.id,
|
id: statusData.id,
|
||||||
url: statusData.urls.original,
|
url: statusData.urls.original,
|
||||||
@@ -134,7 +127,6 @@ export function PhotoUpload({
|
|||||||
thumbnailUrl: statusData.urls.thumbnail
|
thumbnailUrl: statusData.urls.thumbnail
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Wait 1 second before checking again
|
// Wait 1 second before checking again
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
|||||||
Reference in New Issue
Block a user