zhenxun_bot/zhenxun/utils/github_utils/__init__.py
AkashiCoin d3a4a5bbf7
🐛 fix(github_utils): 修复路径解析问题 (#1668)
* 🐛 fix(github_utils): 修复路径解析问题

* chore(version): Update version to v0.2.3-a39d7a3

---------

Co-authored-by: AkashiCoin <AkashiCoin@users.noreply.github.com>
2024-10-02 12:54:12 +08:00

28 lines
890 B
Python

from collections.abc import Generator
from .const import GITHUB_REPO_URL_PATTERN
from .func import get_fastest_raw_formats, get_fastest_archive_formats
from .models import RepoAPI, RepoInfo, GitHubStrategy, JsdelivrStrategy
__all__ = [
"get_fastest_raw_formats",
"get_fastest_archive_formats",
"GithubUtils",
]
class GithubUtils:
# 使用
jsdelivr_api = RepoAPI(JsdelivrStrategy()) # type: ignore
github_api = RepoAPI(GitHubStrategy()) # type: ignore
@classmethod
def iter_api_strategies(cls) -> Generator[RepoAPI]:
yield from [cls.github_api, cls.jsdelivr_api]
@classmethod
def parse_github_url(cls, github_url: str) -> "RepoInfo":
if matched := GITHUB_REPO_URL_PATTERN.match(github_url):
return RepoInfo(**{k: v for k, v in matched.groupdict().items() if v})
raise ValueError("github地址格式错误")