mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-03 02:30:01 +08:00
版本更新
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from collections.abc import Generator
|
||||
|
||||
from .consts import GITHUB_REPO_URL_PATTERN
|
||||
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
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import re
|
||||
|
||||
GITHUB_REPO_URL_PATTERN = re.compile(
|
||||
r"^https://github.com/(?P<owner>[^/]+)/(?P<repo>[^/]+)(/tree/(?P<branch>[^/]+))?$"
|
||||
)
|
||||
"""github仓库地址正则"""
|
||||
|
||||
JSD_PACKAGE_API_FORMAT = (
|
||||
"https://data.jsdelivr.com/v1/packages/gh/{owner}/{repo}@{branch}"
|
||||
)
|
||||
"""jsdelivr包地址格式"""
|
||||
|
||||
GIT_API_TREES_FORMAT = (
|
||||
"https://api.github.com/repos/{owner}/{repo}/git/trees/{branch}?recursive=1"
|
||||
)
|
||||
"""git api trees地址格式"""
|
||||
|
||||
CACHED_API_TTL = 300
|
||||
"""缓存api ttl"""
|
||||
|
||||
RAW_CONTENT_FORMAT = "https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}"
|
||||
"""raw content格式"""
|
||||
|
||||
ARCHIVE_URL_FORMAT = "https://github.com/{owner}/{repo}/archive/refs/heads/{branch}.zip"
|
||||
"""archive url格式"""
|
||||
|
||||
RELEASE_ASSETS_FORMAT = (
|
||||
"https://github.com/{owner}/{repo}/releases/download/{version}/{filename}"
|
||||
)
|
||||
"""release assets格式"""
|
||||
|
||||
RELEASE_SOURCE_FORMAT = (
|
||||
"https://codeload.github.com/{owner}/{repo}/legacy.{compress}/refs/tags/{version}"
|
||||
)
|
||||
"""release 源码格式"""
|
||||
@@ -1,7 +1,7 @@
|
||||
from aiocache import cached
|
||||
|
||||
from ..http_utils import AsyncHttpx
|
||||
from .consts import (
|
||||
from .const import (
|
||||
ARCHIVE_URL_FORMAT,
|
||||
RAW_CONTENT_FORMAT,
|
||||
RELEASE_ASSETS_FORMAT,
|
||||
|
||||
@@ -5,7 +5,7 @@ from strenum import StrEnum
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..http_utils import AsyncHttpx
|
||||
from .consts import CACHED_API_TTL, GIT_API_TREES_FORMAT, JSD_PACKAGE_API_FORMAT
|
||||
from .const import CACHED_API_TTL, GIT_API_TREES_FORMAT, JSD_PACKAGE_API_FORMAT
|
||||
from .func import (
|
||||
get_fastest_raw_formats,
|
||||
get_fastest_archive_formats,
|
||||
@@ -199,13 +199,15 @@ class GitHubStrategy:
|
||||
|
||||
body: TreeInfo
|
||||
|
||||
def export_files(self, module_path: str) -> list[str]:
|
||||
def export_files(self, module_path: str, is_dir: bool) -> list[str]:
|
||||
"""导出文件路径"""
|
||||
tree_info = self.body
|
||||
return [
|
||||
file.path
|
||||
for file in tree_info.tree
|
||||
if file.type == TreeType.FILE and file.path.startswith(module_path)
|
||||
if file.type == TreeType.FILE
|
||||
and file.path.startswith(module_path)
|
||||
and (not is_dir or file.path[len(module_path)] == "/")
|
||||
]
|
||||
|
||||
@classmethod
|
||||
@@ -229,4 +231,4 @@ class GitHubStrategy:
|
||||
|
||||
def get_files(self, module_path: str, is_dir: bool = True) -> list[str]:
|
||||
"""获取文件路径"""
|
||||
return self.export_files(module_path)
|
||||
return self.export_files(module_path, is_dir)
|
||||
|
||||
Reference in New Issue
Block a user