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,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++;
} }