统一前后端代码格式化配置
This commit is contained in:
@@ -12,8 +12,7 @@ const IMAGE_UPLOAD_QUALITY: Record<string, number> = {
|
||||
|
||||
export async function optimizeImageForUpload(file: File, scene: string) {
|
||||
if (!file.type.startsWith('image/')) return file
|
||||
if (!['image/jpeg', 'image/png', 'image/webp'].includes(file.type))
|
||||
return file
|
||||
if (!['image/jpeg', 'image/png', 'image/webp'].includes(file.type)) return file
|
||||
if (typeof document === 'undefined') return file
|
||||
|
||||
const maxSide = IMAGE_UPLOAD_MAX_SIDE[scene] ?? 1600
|
||||
@@ -21,11 +20,7 @@ export async function optimizeImageForUpload(file: File, scene: string) {
|
||||
|
||||
try {
|
||||
const image = await loadImage(file)
|
||||
const { width, height } = fitSize(
|
||||
image.naturalWidth,
|
||||
image.naturalHeight,
|
||||
maxSide,
|
||||
)
|
||||
const { width, height } = fitSize(image.naturalWidth, image.naturalHeight, maxSide)
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = width
|
||||
canvas.height = height
|
||||
@@ -70,11 +65,7 @@ function fitSize(width: number, height: number, maxSide: number) {
|
||||
}
|
||||
}
|
||||
|
||||
function canvasToBlob(
|
||||
canvas: HTMLCanvasElement,
|
||||
type: string,
|
||||
quality: number,
|
||||
) {
|
||||
function canvasToBlob(canvas: HTMLCanvasElement, type: string, quality: number) {
|
||||
return new Promise<Blob | null>((resolve) => {
|
||||
canvas.toBlob(resolve, type, quality)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user