Refactor image model selection and dimensions

This commit is contained in:
Riccardo Giorato
2025-12-23 21:41:38 +01:00
parent ff25be7c85
commit bbe8c8caf8
4 changed files with 132 additions and 41 deletions
+29
View File
@@ -0,0 +1,29 @@
export function validateFileForUpload(file: File, rejectWebP: boolean = true): { valid: boolean; error?: string } {
// Reject WebP files
if (rejectWebP && (file.type === "image/webp" || file.name.toLowerCase().endsWith('.webp'))) {
return {
valid: false,
error: "WebP files not supported. Please upload PNG, JPG, or JPEG files instead of WebP."
}
}
// Check if file is an image
if (!file.type.startsWith("image/")) {
return {
valid: false,
error: "Only image files are supported."
}
}
return { valid: true }
}
export function generateFilePreview(file: File): Promise<string> {
return new Promise((resolve) => {
const reader = new FileReader()
reader.onload = (e) => {
resolve(e.target?.result as string)
}
reader.readAsDataURL(file)
})
}