mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🐛 fix(github_utils): 适配插件仓库根目录语法 (#1784)
This commit is contained in:
parent
4291cda244
commit
c84e99d084
@ -229,12 +229,15 @@ class ShopManage:
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
raise ValueError("所有API获取插件文件失败,请检查网络连接")
|
raise ValueError("所有API获取插件文件失败,请检查网络连接")
|
||||||
|
if module_path == ".":
|
||||||
|
module_path = ""
|
||||||
files = repo_api.get_files(
|
files = repo_api.get_files(
|
||||||
module_path=module_path.replace(".", "/") + ("" if is_dir else ".py"),
|
module_path=module_path.replace(".", "/") + ("" if is_dir else ".py"),
|
||||||
is_dir=is_dir,
|
is_dir=is_dir,
|
||||||
)
|
)
|
||||||
download_urls = [await repo_info.get_raw_download_urls(file) for file in files]
|
download_urls = [await repo_info.get_raw_download_urls(file) for file in files]
|
||||||
base_path = BASE_PATH / "plugins" if is_external else BASE_PATH
|
base_path = BASE_PATH / "plugins" if is_external else BASE_PATH
|
||||||
|
base_path = base_path if module_path else base_path / repo_info.repo
|
||||||
download_paths: list[Path | str] = [base_path / file for file in files]
|
download_paths: list[Path | str] = [base_path / file for file in files]
|
||||||
logger.debug(f"插件下载路径: {download_paths}", "插件管理")
|
logger.debug(f"插件下载路径: {download_paths}", "插件管理")
|
||||||
result = await AsyncHttpx.gather_download_file(download_urls, download_paths)
|
result = await AsyncHttpx.gather_download_file(download_urls, download_paths)
|
||||||
|
|||||||
@ -106,8 +106,8 @@ class JsdelivrStrategy:
|
|||||||
def get_file_paths(self, module_path: str, is_dir: bool = True) -> list[str]:
|
def get_file_paths(self, module_path: str, is_dir: bool = True) -> list[str]:
|
||||||
"""获取文件路径"""
|
"""获取文件路径"""
|
||||||
paths = module_path.split("/")
|
paths = module_path.split("/")
|
||||||
filename = "" if is_dir else paths[-1]
|
filename = "" if is_dir and module_path else paths[-1]
|
||||||
paths = paths if is_dir else paths[:-1]
|
paths = paths if is_dir and module_path else paths[:-1]
|
||||||
cur_file = self.body
|
cur_file = self.body
|
||||||
for path in paths: # 导航到正确的目录
|
for path in paths: # 导航到正确的目录
|
||||||
cur_file = next(
|
cur_file = next(
|
||||||
@ -141,7 +141,8 @@ class JsdelivrStrategy:
|
|||||||
]
|
]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return collect_files(cur_file, "/".join(paths), filename)
|
files = collect_files(cur_file, "/".join(paths), filename)
|
||||||
|
return files if module_path else [f[1:] for f in files]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@cached(ttl=CACHED_API_TTL)
|
@cached(ttl=CACHED_API_TTL)
|
||||||
@ -208,7 +209,7 @@ class GitHubStrategy:
|
|||||||
for file in tree_info.tree
|
for file in tree_info.tree
|
||||||
if file.type == TreeType.FILE
|
if file.type == TreeType.FILE
|
||||||
and file.path.startswith(module_path)
|
and file.path.startswith(module_path)
|
||||||
and (not is_dir or file.path[len(module_path)] == "/")
|
and (not is_dir or file.path[len(module_path)] == "/" or not module_path)
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user