From c69b8bf65dd1bb091204ca2dc4a24959f5f6abab Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Sat, 2 Dec 2023 03:18:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=9B=BE=E7=89=87=E6=97=A0=E6=B3=95=E9=80=9A=E8=BF=87?= =?UTF-8?q?link=5Flocal=E7=9A=84=E5=BD=A2=E5=BC=8F=E5=8F=91=E9=80=81,=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BF=E9=97=AE=E5=90=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4`IMAGE=5FTEMP`=E4=B8=8B=E7=9A=84=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/core.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gsuid_core/core.py b/gsuid_core/core.py index 4c1ee3c..0fa9581 100644 --- a/gsuid_core/core.py +++ b/gsuid_core/core.py @@ -180,18 +180,19 @@ def main(): retcode = -1 return {'status': retcode, 'msg': '', 'data': {}} - def delete_image(image_path: Path): + async def delete_image(image_path: Path): + await asyncio.sleep(180) image_path.unlink() @app.get('/genshinuid/image/{image_id}.jpg') async def get_image(image_id: str, background_tasks: BackgroundTasks): path = image_res / f'{image_id}.jpg' - image = Image.open(path) + image = Image.open(path).convert('RGB') image_bytes = BytesIO() image.save(image_bytes, format='JPEG') image_bytes.seek(0) response = StreamingResponse(image_bytes, media_type='image/png') - # background_tasks.add_task(delete_image, path) + asyncio.create_task(delete_image(path)) return response site.mount_app(app)