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:
pac7
2025-10-08 19:27:31 +00:00
parent f21602b992
commit bfba3baf7e
12 changed files with 224 additions and 110 deletions

View File

@@ -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;
}