Skip to content

Commit

Permalink
🐛 fix(github_utils): 适配插件仓库根目录语法 (#1784)
Browse files Browse the repository at this point in the history
  • Loading branch information
AkashiCoin authored Dec 23, 2024
1 parent 4291cda commit c84e99d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions zhenxun/builtin_plugins/plugin_store/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,15 @@ async def install_plugin_with_repo(
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)
Expand Down
9 changes: 5 additions & 4 deletions zhenxun/utils/github_utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -141,7 +141,8 @@ def collect_files(file: FileInfo, current_path: str, filename: str):
]
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)
Expand Down Expand Up @@ -208,7 +209,7 @@ def export_files(self, module_path: str, is_dir: bool) -> list[str]:
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
Expand Down

0 comments on commit c84e99d

Please sign in to comment.