From 0481e1d45e435bacaa2926581b6f00a6d5485ac0 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 10 Feb 2025 20:13:54 +0800 Subject: [PATCH] fix(core): github mirror not applied successfully --- astrbot/core/config/default.py | 3 ++- astrbot/core/star/star_manager.py | 4 ++-- astrbot/core/star/updator.py | 4 ++-- astrbot/core/zip_updator.py | 20 ++++++++++++-------- astrbot/dashboard/routes/plugin.py | 3 +-- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 81da33e91..7abc0d9e2 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -855,7 +855,8 @@ CONFIG_METADATA_2 = { "plugin_repo_mirror": { "description": "插件仓库镜像", "type": "string", - "hint": "插件仓库的镜像地址,用于加速插件的下载。", + "hint": "已废弃,请使用管理面板->设置页的代理地址选择", + "obvious_hint": True, "options": [ "default", "https://ghp.ci/", diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 3d4d08769..44e8aa565 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -340,8 +340,8 @@ class PluginManager: self.failed_plugin_info = fail_rec return False, fail_rec - async def install_plugin(self, repo_url: str): - plugin_path = await self.updator.install(repo_url) + async def install_plugin(self, repo_url: str, proxy=""): + plugin_path = await self.updator.install(repo_url, proxy) # reload the plugin await self.reload() return plugin_path diff --git a/astrbot/core/star/updator.py b/astrbot/core/star/updator.py index 3ea211432..640fb4abb 100644 --- a/astrbot/core/star/updator.py +++ b/astrbot/core/star/updator.py @@ -15,10 +15,10 @@ class PluginUpdator(RepoZipUpdator): def get_plugin_store_path(self) -> str: return self.plugin_store_path - async def install(self, repo_url: str) -> str: + async def install(self, repo_url: str, proxy="") -> str: repo_name = self.format_repo_name(repo_url) plugin_path = os.path.join(self.plugin_store_path, repo_name) - await self.download_from_repo_url(plugin_path, repo_url) + await self.download_from_repo_url(plugin_path, repo_url, proxy) self.unzip_file(plugin_path + ".zip", plugin_path) return plugin_path diff --git a/astrbot/core/zip_updator.py b/astrbot/core/zip_updator.py index 39cacddde..67003a1bf 100644 --- a/astrbot/core/zip_updator.py +++ b/astrbot/core/zip_updator.py @@ -100,7 +100,7 @@ class RepoZipUpdator(): body=update_data[0]['body'] ) - async def download_from_repo_url(self, target_path: str, repo_url: str): + async def download_from_repo_url(self, target_path: str, repo_url: str, proxy=""): repo_namespace = repo_url.split("/")[-2:] author = repo_namespace[0] repo = repo_namespace[1] @@ -116,13 +116,17 @@ class RepoZipUpdator(): release_url = releases[0]['zipball_url'] # 镜像站点 - match self.repo_mirror: - case 'https://github-mirror.us.kg/': - release_url = self.repo_mirror + release_url - case "https://ghp.ci/": - release_url = self.repo_mirror + release_url - case _: - pass + # match self.repo_mirror: + # case 'https://github-mirror.us.kg/': + # release_url = self.repo_mirror + release_url + # case "https://ghp.ci/": + # release_url = self.repo_mirror + release_url + # case _: + # pass + + if proxy: + release_url = f"{proxy}/{release_url}" + logger.info(f"使用代理下载: {release_url}") await download_file(release_url, target_path + ".zip") diff --git a/astrbot/dashboard/routes/plugin.py b/astrbot/dashboard/routes/plugin.py index c75ec2294..a4fc3eea3 100644 --- a/astrbot/dashboard/routes/plugin.py +++ b/astrbot/dashboard/routes/plugin.py @@ -146,11 +146,10 @@ class PluginRoute(Route): proxy: str = post_data.get("proxy", None) if proxy: proxy = proxy.removesuffix("/") - repo_url = f"{proxy}/{repo_url}" try: logger.info(f"正在安装插件 {repo_url}") - await self.plugin_manager.install_plugin(repo_url) + await self.plugin_manager.install_plugin(repo_url, proxy) self.core_lifecycle.restart() logger.info(f"安装插件 {repo_url} 成功。") return Response().ok(None, "安装成功。").__dict__