From c40b5b3d33bc8382abd3172cfada9eff20a24576 Mon Sep 17 00:00:00 2001 From: crazywoola <427733928@qq.com> Date: Mon, 25 Nov 2024 22:32:38 +0800 Subject: [PATCH] add: type --- web/app/components/base/app-icon-picker/index.tsx | 12 +++++++----- web/app/components/base/app-icon-picker/utils.ts | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/web/app/components/base/app-icon-picker/index.tsx b/web/app/components/base/app-icon-picker/index.tsx index 8a10d28653..6ff28e7924 100644 --- a/web/app/components/base/app-icon-picker/index.tsx +++ b/web/app/components/base/app-icon-picker/index.tsx @@ -69,7 +69,7 @@ const AppIconPicker: FC = ({ }, }) - const [imageCropInfo, setImageCropInfo] = useState<{ tempUrl: string; croppedAreaPixels: Area; fileName: string }>() + const [imageCropInfo, setImageCropInfo] = useState<{ tempUrl: string; croppedAreaPixels: Area; fileName: string; file?: File }>() const handleImageCropped = async (tempUrl: string, croppedAreaPixels: Area, fileName: string) => { setImageCropInfo({ tempUrl, croppedAreaPixels, fileName }) } @@ -93,13 +93,15 @@ const AppIconPicker: FC = ({ if (!imageCropInfo && !uploadImageInfo) return setUploading(true) - if (imageCropInfo.file) { + if (imageCropInfo?.file) { handleLocalFileUpload(imageCropInfo.file) return } - const blob = await getCroppedImg(imageCropInfo.tempUrl, imageCropInfo.croppedAreaPixels, imageCropInfo.fileName) - const file = new File([blob], imageCropInfo.fileName, { type: blob.type }) - handleLocalFileUpload(file) + if (imageCropInfo) { + const blob = await getCroppedImg(imageCropInfo.tempUrl, imageCropInfo.croppedAreaPixels, imageCropInfo.fileName) + const file = new File([blob], imageCropInfo.fileName, { type: blob.type }) + handleLocalFileUpload(file) + } } } diff --git a/web/app/components/base/app-icon-picker/utils.ts b/web/app/components/base/app-icon-picker/utils.ts index 99154d56da..9885626b11 100644 --- a/web/app/components/base/app-icon-picker/utils.ts +++ b/web/app/components/base/app-icon-picker/utils.ts @@ -116,7 +116,7 @@ export default async function getCroppedImg( }) } -export function checkIsAnimatedImage(file) { +export function checkIsAnimatedImage(file: Blob) { return new Promise((resolve, reject) => { const fileReader = new FileReader() @@ -148,7 +148,7 @@ export function checkIsAnimatedImage(file) { } // Function to check for WebP signature -function isWebP(arr) { +function isWebP(arr: Uint8Array): boolean { return ( arr[0] === 0x52 && arr[1] === 0x49 && arr[2] === 0x46 && arr[3] === 0x46 && arr[8] === 0x57 && arr[9] === 0x45 && arr[10] === 0x42 && arr[11] === 0x50 @@ -156,7 +156,7 @@ function isWebP(arr) { } // Function to check if the WebP is animated (contains ANIM chunk) -function checkWebPAnimation(arr) { +function checkWebPAnimation(arr: string | any[] | Uint8Array) { // Search for the ANIM chunk in WebP to determine if it's animated for (let i = 12; i < arr.length - 4; i++) { if (arr[i] === 0x41 && arr[i + 1] === 0x4E && arr[i + 2] === 0x49 && arr[i + 3] === 0x4D)