mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
🐛 修复部分图片无法通过link_local的形式发送, 新增访问后自动删除IMAGE_TEMP
下的图片
This commit is contained in:
parent
b9dc7312a1
commit
c69b8bf65d
@ -180,18 +180,19 @@ def main():
|
|||||||
retcode = -1
|
retcode = -1
|
||||||
return {'status': retcode, 'msg': '', 'data': {}}
|
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()
|
image_path.unlink()
|
||||||
|
|
||||||
@app.get('/genshinuid/image/{image_id}.jpg')
|
@app.get('/genshinuid/image/{image_id}.jpg')
|
||||||
async def get_image(image_id: str, background_tasks: BackgroundTasks):
|
async def get_image(image_id: str, background_tasks: BackgroundTasks):
|
||||||
path = image_res / f'{image_id}.jpg'
|
path = image_res / f'{image_id}.jpg'
|
||||||
image = Image.open(path)
|
image = Image.open(path).convert('RGB')
|
||||||
image_bytes = BytesIO()
|
image_bytes = BytesIO()
|
||||||
image.save(image_bytes, format='JPEG')
|
image.save(image_bytes, format='JPEG')
|
||||||
image_bytes.seek(0)
|
image_bytes.seek(0)
|
||||||
response = StreamingResponse(image_bytes, media_type='image/png')
|
response = StreamingResponse(image_bytes, media_type='image/png')
|
||||||
# background_tasks.add_task(delete_image, path)
|
asyncio.create_task(delete_image(path))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
site.mount_app(app)
|
site.mount_app(app)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user