feat: harden CMPP delivery and platform workflows
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
export const IMAGE_UPLOAD_MAX_BYTES = 2 * 1024 * 1024;
|
||||
export const FILE_UPLOAD_MAX_BYTES = 10 * 1024 * 1024;
|
||||
|
||||
const IMAGE_FILE_EXTENSION = /\.(?:avif|bmp|gif|heic|heif|jpe?g|png|svg|webp)$/i;
|
||||
|
||||
export function isImageUpload(file: Pick<File, 'name' | 'type'>) {
|
||||
return file.type.toLowerCase().startsWith('image/') || IMAGE_FILE_EXTENSION.test(file.name);
|
||||
}
|
||||
|
||||
export function assertUploadFileSize(file: Pick<File, 'name' | 'size' | 'type'>) {
|
||||
const image = isImageUpload(file);
|
||||
const limit = image ? IMAGE_UPLOAD_MAX_BYTES : FILE_UPLOAD_MAX_BYTES;
|
||||
if (file.size > limit) {
|
||||
throw new Error(image ? '图片大小不能超过 2MB' : '文件大小不能超过 10MB');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user