mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-15 09:50:20 +08:00
fix downloading
This commit is contained in:
parent
7fbe1ecb9c
commit
a0d26a9391
@ -1,10 +1,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
import requests
|
||||||
|
|
||||||
from src.models.github import GithubResponse
|
from src.models.github import GithubResponse
|
||||||
from src.models.requests import NoChromeExtentionError
|
from src.models.requests import NoChromeExtentionError
|
||||||
@ -40,17 +42,19 @@ def download_extentions():
|
|||||||
path = Path(f"{EXTENTIONS_PATH}/{extention_name}")
|
path = Path(f"{EXTENTIONS_PATH}/{extention_name}")
|
||||||
try:
|
try:
|
||||||
extention = get_latest_github_release(repository)
|
extention = get_latest_github_release(repository)
|
||||||
|
logger.info(
|
||||||
|
f"Downloading {extention_name} from {extention.browser_download_url}"
|
||||||
|
)
|
||||||
except httpx.NetworkError:
|
except httpx.NetworkError:
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
|
logger.error(f"Error downloading {extention_name}, using local copy")
|
||||||
downloaded_extentions.append(path.as_posix())
|
downloaded_extentions.append(path.as_posix())
|
||||||
continue
|
continue
|
||||||
response = httpx.get(extention.browser_download_url)
|
zip_file = requests.get(extention.browser_download_url, timeout=10)
|
||||||
Path(EXTENTIONS_PATH).mkdir(exist_ok=True)
|
Path(EXTENTIONS_PATH).mkdir(exist_ok=True)
|
||||||
if not Path(f"{EXTENTIONS_PATH}/{extention.name}").is_file():
|
with ZipFile(io.BytesIO(zip_file.content)) as zip_obj:
|
||||||
with Path(f"{EXTENTIONS_PATH}/{extention.name}").open("wb") as f:
|
|
||||||
f.write(response.content)
|
|
||||||
|
|
||||||
with ZipFile(f"{EXTENTIONS_PATH}/{extention.name}", "r") as zip_obj:
|
|
||||||
zip_obj.extractall(f"{EXTENTIONS_PATH}/{extention_name}")
|
zip_obj.extractall(f"{EXTENTIONS_PATH}/{extention_name}")
|
||||||
|
logger.debug(f"Extracted {extention_name} to {path}")
|
||||||
|
|
||||||
|
logger.info(f"Successfully downloaded {extention_name} to {path}")
|
||||||
downloaded_extentions.append(path.as_posix())
|
downloaded_extentions.append(path.as_posix())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user