fix(core): github mirror not applied successfully

This commit is contained in:
Soulter
2025-02-10 20:13:54 +08:00
parent 3177b61421
commit 0481e1d45e
5 changed files with 19 additions and 15 deletions
+2 -1
View File
@@ -855,7 +855,8 @@ CONFIG_METADATA_2 = {
"plugin_repo_mirror": {
"description": "插件仓库镜像",
"type": "string",
"hint": "插件仓库的镜像地址,用于加速插件的下载。",
"hint": "已废弃,请使用管理面板->设置页的代理地址选择",
"obvious_hint": True,
"options": [
"default",
"https://ghp.ci/",
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
+12 -8
View File
@@ -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")
+1 -2
View File
@@ -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__