mirror of
https://github.com/smallevilbeast/ntchat.git
synced 2025-07-07 20:37:36 +08:00
修复python3.6运行bug
This commit is contained in:
parent
cf69a36a72
commit
5ff92ea0c7
|
@ -1,8 +1,15 @@
|
||||||
import os.path
|
import os.path
|
||||||
import time
|
|
||||||
import requests
|
import requests
|
||||||
from xdg import get_download_dir
|
from xdg import get_download_dir
|
||||||
from models import SendMediaReqModel
|
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):
|
def get_local_path(model: SendMediaReqModel):
|
||||||
|
@ -11,7 +18,7 @@ def get_local_path(model: SendMediaReqModel):
|
||||||
if not model.url:
|
if not model.url:
|
||||||
return None
|
return None
|
||||||
data = requests.get(model.url).content
|
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:
|
with open(temp_file, 'wb') as fp:
|
||||||
fp.write(data)
|
fp.write(data)
|
||||||
return temp_file
|
return temp_file
|
||||||
|
|
Loading…
Reference in New Issue
Block a user