From 9b1fa22cbe23c9eaa1812d192d89a58adb609437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Sun, 17 Nov 2024 22:45:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20=E4=BF=AE=E5=A4=8Dfile=5Fsize?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=AF=BC=E8=87=B4=E7=9A=84hint?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/post/tp-emoticon.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/post/tp-emoticon.vue b/src/components/post/tp-emoticon.vue index a02a6360..1554e167 100644 --- a/src/components/post/tp-emoticon.vue +++ b/src/components/post/tp-emoticon.vue @@ -31,7 +31,7 @@ interface TpCustomEmoticon { size: { width: number; height: number; - file_size: number; + file_size?: number; }; is_available: boolean; hash: string; @@ -69,15 +69,20 @@ function getImageUrl(): string { async function download(): Promise { const image = props.data.insert.custom_emoticon.url; if (buffer.value === null) buffer.value = await getImageBuffer(image); - const size = bytesToSize(props.data.insert.custom_emoticon.size.file_size); - if (buffer.value.byteLength > 80000000) { - showSnackbar.warn(`图片过大(${size}),无法下载到本地`); + let size = 0; + if (props.data.insert.custom_emoticon.size.file_size) { + size = props.data.insert.custom_emoticon.size.file_size; + } else { + size = buffer.value.byteLength; + } + if (size > 80000000) { + showSnackbar.warn(`图片过大(${bytesToSize(size)}),无法下载到本地`); return; } const format = image.split(".").pop(); const title = props.data.insert.custom_emoticon.hash; await saveCanvasImg(buffer.value, props.data.insert.custom_emoticon.hash, format); - showSnackbar.success(`已保存${title}.${format}到本地,大小为${size}`); + showSnackbar.success(`已保存${title}.${format}到本地,大小为${bytesToSize(size)}`); }