From c84e99d084a7fa3c51ccd2772193692186fa76d5 Mon Sep 17 00:00:00 2001 From: AkashiCoin Date: Mon, 23 Dec 2024 10:09:38 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=20fix(github=5Futils):=20=E9=80=82?= =?UTF-8?q?=E9=85=8D=E6=8F=92=E4=BB=B6=E4=BB=93=E5=BA=93=E6=A0=B9=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=AF=AD=E6=B3=95=20(#1784)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/builtin_plugins/plugin_store/data_source.py | 3 +++ zhenxun/utils/github_utils/models.py | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/zhenxun/builtin_plugins/plugin_store/data_source.py b/zhenxun/builtin_plugins/plugin_store/data_source.py index 21c977aa..4def6c39 100644 --- a/zhenxun/builtin_plugins/plugin_store/data_source.py +++ b/zhenxun/builtin_plugins/plugin_store/data_source.py @@ -229,12 +229,15 @@ class ShopManage: continue else: raise ValueError("所有API获取插件文件失败,请检查网络连接") + if module_path == ".": + module_path = "" files = repo_api.get_files( module_path=module_path.replace(".", "/") + ("" if is_dir else ".py"), is_dir=is_dir, ) 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 if module_path else base_path / repo_info.repo download_paths: list[Path | str] = [base_path / file for file in files] logger.debug(f"插件下载路径: {download_paths}", "插件管理") result = await AsyncHttpx.gather_download_file(download_urls, download_paths) diff --git a/zhenxun/utils/github_utils/models.py b/zhenxun/utils/github_utils/models.py index 14f9a5ac..972889bb 100644 --- a/zhenxun/utils/github_utils/models.py +++ b/zhenxun/utils/github_utils/models.py @@ -106,8 +106,8 @@ class JsdelivrStrategy: def get_file_paths(self, module_path: str, is_dir: bool = True) -> list[str]: """获取文件路径""" paths = module_path.split("/") - filename = "" if is_dir else paths[-1] - paths = paths if is_dir else paths[:-1] + filename = "" if is_dir and module_path else paths[-1] + paths = paths if is_dir and module_path else paths[:-1] cur_file = self.body for path in paths: # 导航到正确的目录 cur_file = next( @@ -141,7 +141,8 @@ class JsdelivrStrategy: ] 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 @cached(ttl=CACHED_API_TTL) @@ -208,7 +209,7 @@ class GitHubStrategy: for file in tree_info.tree if file.type == TreeType.FILE 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