-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎈 perf(github_utils): 支持github url下载遍历
- Loading branch information
1 parent
f2e354e
commit c4f98e3
Showing
8 changed files
with
152 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
from collections.abc import Generator | ||
|
||
from .consts import GITHUB_REPO_URL_PATTERN | ||
from .func import get_fastest_raw_format, get_fastest_archive_format | ||
from .func import get_fastest_raw_formats, get_fastest_archive_formats | ||
from .models import RepoAPI, RepoInfo, GitHubStrategy, JsdelivrStrategy | ||
|
||
__all__ = [ | ||
"parse_github_url", | ||
"get_fastest_raw_format", | ||
"get_fastest_archive_format", | ||
"api_strategy", | ||
"get_fastest_raw_formats", | ||
"get_fastest_archive_formats", | ||
"GithubUtils", | ||
] | ||
|
||
|
||
def parse_github_url(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地址格式错误") | ||
|
||
class GithubUtils: | ||
# 使用 | ||
jsdelivr_api = RepoAPI(JsdelivrStrategy()) # type: ignore | ||
github_api = RepoAPI(GitHubStrategy()) # type: ignore | ||
|
||
# 使用 | ||
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] | ||
|
||
api_strategy = [github_api, 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地址格式错误") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.