mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 12:51:13 -05:00
Fix avatar upload timeout
This commit is contained in:
@@ -113,29 +113,41 @@ export function PhotoUpload({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Poll for upload completion and get final URLs
|
// Step 3: Poll for upload completion and get final URLs
|
||||||
const maxAttempts = 30; // 30 seconds maximum wait
|
const maxAttempts = 60; // 30 seconds maximum wait with faster polling
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
|
|
||||||
while (attempts < maxAttempts) {
|
while (attempts < maxAttempts) {
|
||||||
const { data: statusData, error: statusError } = await supabase.functions.invoke('upload-image', {
|
try {
|
||||||
method: 'GET',
|
// Use direct fetch with URL parameters instead of supabase.functions.invoke with body
|
||||||
body: { id }
|
const response = await fetch(`https://ydvtmnrszybqnbcqbdcy.supabase.co/functions/v1/upload-image?imageId=${encodeURIComponent(id)}`, {
|
||||||
});
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!statusError && statusData?.success && statusData.uploaded && statusData.urls) {
|
if (response.ok) {
|
||||||
const imageUrl = isAvatar ? statusData.urls.avatar : statusData.urls.original;
|
const statusData = await response.json();
|
||||||
const thumbUrl = isAvatar ? statusData.urls.avatar : statusData.urls.thumbnail;
|
|
||||||
|
|
||||||
return {
|
if (statusData?.success && statusData.uploaded && statusData.urls) {
|
||||||
id: statusData.id,
|
const imageUrl = isAvatar ? statusData.urls.avatar : statusData.urls.original;
|
||||||
url: imageUrl,
|
const thumbUrl = isAvatar ? statusData.urls.avatar : statusData.urls.thumbnail;
|
||||||
filename: file.name,
|
|
||||||
thumbnailUrl: thumbUrl
|
return {
|
||||||
};
|
id: statusData.id,
|
||||||
|
url: imageUrl,
|
||||||
|
filename: file.name,
|
||||||
|
thumbnailUrl: thumbUrl
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Status poll error:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait 1 second before checking again
|
// Wait 500ms before checking again (faster polling)
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
attempts++;
|
attempts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user