fix: file name parse

This commit is contained in:
xtaodada 2023-08-12 11:36:51 +08:00
parent 4b60202f11
commit 8eeb844a90
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 15 additions and 2 deletions

View File

@ -157,8 +157,19 @@ def deprecated_to_text(func):
return wrapper
def parse_file_name(file: File) -> str:
support_image_map = {"jpeg": "jpg", "webp": "webp", "png": "png"}
if file.type.startswith("image"):
_, ext = file.type.split("/")
if ext in support_image_map:
ext = support_image_map[ext]
if not file.name.lower().endswith(f".{ext}"):
return file.name + f".{ext}"
return file.name
async def fetch_document(host: str, file: File) -> Optional[str]:
file_name = "downloads/" + file.name
file_name = "downloads/" + parse_file_name(file)
file_url = file.url
if file.size > 100 * 1024 * 1024:
return file_url

View File

@ -11,4 +11,6 @@ async def delete_file(file: str):
def add_delete_file_job(file: str, seconds: int = 10 * 60):
scheduler.add_job(delete_file, "interval", args=[file], seconds=seconds)
if job := scheduler.get_job(f"df_{file}"):
job.remove()
scheduler.add_job(delete_file, "interval", args=[file], seconds=seconds, id=f"df_{file}")