mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-15 17:50:21 +08:00
add github extention parsing and use clean approach
This commit is contained in:
parent
9f09cd8c27
commit
754252a979
@ -12,6 +12,13 @@ CHALLENGE_TITLES = [
|
|||||||
"DDoS-Guard",
|
"DDoS-Guard",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
GITHUB_WEBSITES = [
|
||||||
|
"https://github.com/",
|
||||||
|
"https://www.github.com/",
|
||||||
|
"github.com",
|
||||||
|
"www.github.com",
|
||||||
|
]
|
||||||
|
|
||||||
EXTENTION_REPOSITIORIES = [
|
EXTENTION_REPOSITIORIES = [
|
||||||
"OhMyGuus/I-Still-Dont-Care-About-Cookies",
|
"OhMyGuus/I-Still-Dont-Care-About-Cookies",
|
||||||
"uBlockOrigin/uBOL-home",
|
"uBlockOrigin/uBOL-home",
|
||||||
|
@ -11,15 +11,30 @@ 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
|
||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
from src.utils.consts import EXTENTION_REPOSITIORIES, EXTENTIONS_PATH
|
from src.utils.consts import EXTENTION_REPOSITIORIES, EXTENTIONS_PATH, GITHUB_WEBSITES
|
||||||
|
|
||||||
downloaded_extentions: list[str] = [] # Do not modify, use download_extentions()
|
|
||||||
|
|
||||||
|
|
||||||
def get_latest_github_release(url: str):
|
def get_latest_github_chrome_release(url: str):
|
||||||
"""Get the latest release from GitHub."""
|
"""
|
||||||
url = "https://api.github.com/repos/" + url
|
Get the latest release for chrome from GitHub for a given repository URL.
|
||||||
url += "/releases/latest"
|
|
||||||
|
Args:
|
||||||
|
----
|
||||||
|
url (str): The URL of the GitHub repository.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
-------
|
||||||
|
GithubResponse: The latest release asset with 'chrom' in its name.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
------
|
||||||
|
httpx.NetworkError: If the request to GitHub API returns a 403 Forbidden status code.
|
||||||
|
NoChromeExtentionError: If no release asset with 'chrom' in its name is found.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if url.startswith(tuple(GITHUB_WEBSITES)):
|
||||||
|
url = "/".join(url.split("/")[-2:])
|
||||||
|
url = "https://api.github.com/repos/" + url + "/releases/latest"
|
||||||
|
|
||||||
response = httpx.get(url)
|
response = httpx.get(url)
|
||||||
if response.status_code == httpx.codes.FORBIDDEN:
|
if response.status_code == httpx.codes.FORBIDDEN:
|
||||||
@ -36,12 +51,24 @@ def get_latest_github_release(url: str):
|
|||||||
|
|
||||||
|
|
||||||
def download_extentions():
|
def download_extentions():
|
||||||
"""Download the extention."""
|
"""
|
||||||
|
Download extensions from the specified repositories and saves them locally.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
list[str]: A list of paths to the downloaded extensions.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
httpx.NetworkError: If there is an error downloading an extension.
|
||||||
|
|
||||||
|
"""
|
||||||
|
downloaded_extentions: list[str] = []
|
||||||
for repository in EXTENTION_REPOSITIORIES:
|
for repository in EXTENTION_REPOSITIORIES:
|
||||||
extention_name = repository.split("/")[-1]
|
extention_name = repository.split("/")[-1]
|
||||||
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_chrome_release(repository)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Downloading {extention_name} from {extention.browser_download_url}"
|
f"Downloading {extention_name} from {extention.browser_download_url}"
|
||||||
)
|
)
|
||||||
@ -58,3 +85,4 @@ def download_extentions():
|
|||||||
|
|
||||||
logger.info(f"Successfully downloaded {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())
|
||||||
|
return downloaded_extentions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user