Update pyUltroid/fns/helper.py
Browse files"fix: save downloaded files to temp directory to avoid permission errors"
- pyUltroid/fns/helper.py +6 -2
pyUltroid/fns/helper.py
CHANGED
@@ -14,6 +14,7 @@ import time
|
|
14 |
from traceback import format_exc
|
15 |
from urllib.parse import unquote
|
16 |
from urllib.request import urlretrieve
|
|
|
17 |
|
18 |
from .. import run_as_module
|
19 |
|
@@ -372,9 +373,12 @@ async def download_file(link, name, validate=False):
|
|
372 |
async def _download(content):
|
373 |
if validate and "application/json" in content.headers.get("Content-Type"):
|
374 |
return None, await content.json()
|
375 |
-
|
|
|
|
|
|
|
376 |
file.write(await content.read())
|
377 |
-
return
|
378 |
|
379 |
return await async_searcher(link, evaluate=_download)
|
380 |
|
|
|
14 |
from traceback import format_exc
|
15 |
from urllib.parse import unquote
|
16 |
from urllib.request import urlretrieve
|
17 |
+
import tempfile
|
18 |
|
19 |
from .. import run_as_module
|
20 |
|
|
|
373 |
async def _download(content):
|
374 |
if validate and "application/json" in content.headers.get("Content-Type"):
|
375 |
return None, await content.json()
|
376 |
+
# Always use a temp directory for saving the file
|
377 |
+
temp_dir = tempfile.gettempdir()
|
378 |
+
temp_path = os.path.join(temp_dir, name)
|
379 |
+
with open(temp_path, "wb") as file:
|
380 |
file.write(await content.read())
|
381 |
+
return temp_path, ""
|
382 |
|
383 |
return await async_searcher(link, evaluate=_download)
|
384 |
|