Skip to content

Commit

Permalink
💄 修复file_size不存在导致的hint异常
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Nov 17, 2024
1 parent 63929bc commit 9b1fa22
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/post/tp-emoticon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface TpCustomEmoticon {
size: {
width: number;
height: number;
file_size: number;
file_size?: number;
};
is_available: boolean;
hash: string;
Expand Down Expand Up @@ -69,15 +69,20 @@ function getImageUrl(): string {
async function download(): Promise<void> {
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;

Check warning on line 72 in src/components/post/tp-emoticon.vue

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused assignment

Variable initializer is redundant
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)}`);
}
</script>
<style lang="css" scoped>
Expand Down

0 comments on commit 9b1fa22

Please sign in to comment.