Fix avatar upload timeout

This commit is contained in:
gpt-engineer-app[bot]
2025-09-28 17:43:42 +00:00
parent 2147514784
commit 9c9f519fc2

View File

@@ -113,16 +113,24 @@ 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 {
// Use direct fetch with URL parameters instead of supabase.functions.invoke with body
const response = await fetch(`https://ydvtmnrszybqnbcqbdcy.supabase.co/functions/v1/upload-image?imageId=${encodeURIComponent(id)}`, {
method: 'GET', method: 'GET',
body: { id } 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 statusData = await response.json();
if (statusData?.success && statusData.uploaded && statusData.urls) {
const imageUrl = isAvatar ? statusData.urls.avatar : statusData.urls.original; const imageUrl = isAvatar ? statusData.urls.avatar : statusData.urls.original;
const thumbUrl = isAvatar ? statusData.urls.avatar : statusData.urls.thumbnail; const thumbUrl = isAvatar ? statusData.urls.avatar : statusData.urls.thumbnail;
@@ -133,9 +141,13 @@ export function PhotoUpload({
thumbnailUrl: thumbUrl 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++;
} }