This commit is contained in:
2026-08-07 19:23:46 +08:00
parent aa6c349fce
commit 0b2380689c
10 changed files with 77 additions and 52 deletions
+6 -3
View File
@@ -1,11 +1,14 @@
const allowedTypes = new Set(['image/jpeg', 'image/png'])
const allowedExtensions = new Set(['jpg', 'jpeg', 'png'])
const allowedImageTypes: Readonly<Record<string, ReadonlySet<string>>> = {
'image/jpeg': new Set(['jpg', 'jpeg']),
'image/png': new Set(['png']),
}
export const PRODUCT_IMAGE_MAX_SIZE = 5 * 1024 * 1024
export function validateProductImageFile(file: Pick<File, 'name' | 'size' | 'type'>) {
const extension = file.name.split('.').pop()?.toLowerCase() ?? ''
if (!allowedTypes.has(file.type.toLowerCase()) || !allowedExtensions.has(extension)) {
const allowedExtensions = allowedImageTypes[file.type.toLowerCase()]
if (!allowedExtensions?.has(extension)) {
return '产品图片仅支持 JPG、JPEG、PNG 格式'
}
if (file.size <= 0) return '产品图片内容为空'