mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 12:51:14 -05:00
Improve component stability and user experience with safety checks
Implement robust error handling, safety checks for data structures, and state management improvements across various components to prevent runtime errors and enhance user experience. Replit-Commit-Author: Agent Replit-Commit-Session-Id: a71e826a-1d38-4b6e-a34f-fbf5ba1f1b25 Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -393,53 +393,3 @@ export function EntityMultiImageUploader({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Helper function to upload all local files
|
||||
export async function uploadPendingImages(images: UploadedImage[]): Promise<UploadedImage[]> {
|
||||
const uploadedImages: UploadedImage[] = [];
|
||||
|
||||
for (const image of images) {
|
||||
if (image.isLocal && image.file) {
|
||||
try {
|
||||
// Get upload URL from Cloudflare
|
||||
const { data: uploadData, error: uploadError } = await fetch('/api/upload-image', {
|
||||
method: 'POST',
|
||||
}).then(res => res.json());
|
||||
|
||||
if (uploadError) {
|
||||
throw new Error('Failed to get upload URL');
|
||||
}
|
||||
|
||||
// Upload to Cloudflare
|
||||
const formData = new FormData();
|
||||
formData.append('file', image.file);
|
||||
|
||||
const uploadResponse = await fetch(uploadData.uploadURL, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!uploadResponse.ok) {
|
||||
throw new Error('Failed to upload image');
|
||||
}
|
||||
|
||||
const result = await uploadResponse.json();
|
||||
|
||||
// Return uploaded image with Cloudflare data
|
||||
uploadedImages.push({
|
||||
url: result.result.variants[0],
|
||||
cloudflare_id: result.result.id,
|
||||
caption: image.caption,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error uploading image:', error);
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
// Already uploaded, keep as is
|
||||
uploadedImages.push(image);
|
||||
}
|
||||
}
|
||||
|
||||
return uploadedImages;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user