mirror of
https://github.com/smallevilbeast/ntchat.git
synced 2025-05-24 00:56:07 +08:00
18 lines
469 B
Python
18 lines
469 B
Python
import os.path
|
|
import time
|
|
import requests
|
|
from xdg import get_download_dir
|
|
from models import SendMediaReqModel
|
|
|
|
|
|
def get_local_path(model: SendMediaReqModel):
|
|
if os.path.isfile(model.file_path):
|
|
return model.file_path
|
|
if not model.url:
|
|
return None
|
|
data = requests.get(model.url).content
|
|
temp_file = os.path.join(get_download_dir(), str(time.time_ns()))
|
|
with open(temp_file, 'wb') as fp:
|
|
fp.write(data)
|
|
return temp_file
|