From 9438a3169dfda166776610ba6aac1ac168231636 Mon Sep 17 00:00:00 2001 From: molvqingtai Date: Wed, 6 Nov 2024 18:24:43 +0800 Subject: [PATCH] perf: optimize image processing --- src/app/content/views/Footer/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/content/views/Footer/index.tsx b/src/app/content/views/Footer/index.tsx index f67182d..b25c771 100644 --- a/src/app/content/views/Footer/index.tsx +++ b/src/app/content/views/Footer/index.tsx @@ -250,7 +250,13 @@ const Footer: FC = () => { const handleInjectImage = async (file: File) => { try { setInputLoading(true) - const blob = await compressImage({ input: file, targetSize: 30 * 1024, outputType: 'image/webp' }) + + const blob = await compressImage({ + input: file, + targetSize: 30 * 1024, + outputType: file.size > 30 * 1024 ? 'image/webp' : undefined + }) + const base64 = await blobToBase64(blob) const hash = nanoid() const newMessage = `${message.slice(0, selectionEnd)}![Image](hash:${hash})${message.slice(selectionEnd)}`