From 5ff92ea0c7a2b0fd5b9acc6b91fb4b63c9d74648 Mon Sep 17 00:00:00 2001 From: evilbeast Date: Tue, 13 Sep 2022 21:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpython3.6=E8=BF=90=E8=A1=8Cbu?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi_example/down.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fastapi_example/down.py b/fastapi_example/down.py index 8fb9699..b00582d 100644 --- a/fastapi_example/down.py +++ b/fastapi_example/down.py @@ -1,8 +1,15 @@ import os.path -import time import requests from xdg import get_download_dir from models import SendMediaReqModel +from ntchat.utils import generate_guid + + +def new_download_file(): + while True: + path = os.path.join(get_download_dir(), generate_guid("temp")) + if not os.path.isfile(path): + return path def get_local_path(model: SendMediaReqModel): @@ -11,7 +18,7 @@ def get_local_path(model: SendMediaReqModel): if not model.url: return None data = requests.get(model.url).content - temp_file = os.path.join(get_download_dir(), str(time.time_ns())) + temp_file = new_download_file() with open(temp_file, 'wb') as fp: fp.write(data) return temp_file