mirror of
https://github.com/Xtao-Labs/misskey2telegram.git
synced 2024-11-22 05:53:09 +00:00
fix: file name parse
This commit is contained in:
parent
4b60202f11
commit
8eeb844a90
@ -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
|
||||
|
@ -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}")
|
||||
|
Loading…
Reference in New Issue
Block a user