From 89bdad9943e2037eb07cd113d7b631fe44e1c5c9 Mon Sep 17 00:00:00 2001 From: morvanzhou Date: Fri, 26 Jul 2024 10:28:03 +0800 Subject: [PATCH] feat(app): - fix bug --- src/retk/core/files/saver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/retk/core/files/saver.py b/src/retk/core/files/saver.py index 5339e23..5d38435 100644 --- a/src/retk/core/files/saver.py +++ b/src/retk/core/files/saver.py @@ -19,11 +19,14 @@ from retk.models.client import client from retk.models.tps import UserFile +RESIZE_IMAGE_TYPE = {".png", ".jpg", ".jpeg"} + @dataclass class File: data: BinaryIO filename: str + ext: str = "" def __post_init__(self): self.data.seek(0) @@ -39,8 +42,10 @@ def __post_init__(self): self._reset_size() def image_resize(self, resize_threshold: int): - if self.ext == ".gif" or self.type != FileTypesEnum.IMAGE: + if self.type != FileTypesEnum.IMAGE or self.ext not in RESIZE_IMAGE_TYPE: return + if self.ext.lower() == ".jpg": + self.ext = ".jpeg" if self.size > resize_threshold: # reduce image size out = io.BytesIO()