🐛 修复添加插件依赖更新

This commit is contained in:
HibiKier 2025-01-17 12:45:30 +08:00
parent d0b1024566
commit 2b3aaf4246
6 changed files with 215 additions and 10 deletions

183
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -43,6 +43,7 @@ aiocache = "^0.12.2"
py-cpuinfo = "^9.0.0"
nonebot-plugin-uninfo = "^0.4.1"
nonebot-plugin-alconna = "^0.54.0"
tenacity = "^9.0.0"
[tool.poetry.group.dev.dependencies]
nonebug = "^0.4"

View File

@ -44,14 +44,14 @@ _matcher = on_alconna(
)
_matcher.shortcut(
r"添加插件",
r"(添加|安装)插件",
command="插件商店",
arguments=["add", "{%0}"],
prefix=True,
)
_matcher.shortcut(
r"移除插件",
r"(移除|卸载)插件",
command="插件商店",
arguments=["remove", "{%0}"],
prefix=True,

View File

@ -232,8 +232,9 @@ class ShopManage:
raise ValueError("所有API获取插件文件失败请检查网络连接")
if module_path == ".":
module_path = ""
replace_module_path = module_path.replace(".", "/")
files = repo_api.get_files(
module_path=module_path.replace(".", "/") + ("" if is_dir else ".py"),
module_path=replace_module_path + ("" if is_dir else ".py"),
is_dir=is_dir,
)
download_urls = [await repo_info.get_raw_download_urls(file) for file in files]
@ -248,8 +249,12 @@ class ShopManage:
else:
# 安装依赖
plugin_path = base_path / "/".join(module_path.split("."))
req_files = repo_api.get_files(REQ_TXT_FILE_STRING, False)
req_files.extend(repo_api.get_files("requirement.txt", False))
req_files = repo_api.get_files(
f"{replace_module_path}/{REQ_TXT_FILE_STRING}", False
)
req_files.extend(
repo_api.get_files(f"{replace_module_path}/requirement.txt", False)
)
logger.debug(f"获取插件依赖文件列表: {req_files}", "插件管理")
req_download_urls = [
await repo_info.get_raw_download_urls(file) for file in req_files

View File

@ -0,0 +1,16 @@
from httpx import ConnectError, HTTPStatusError, TimeoutException
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed
class Retry:
@staticmethod
def api():
"""接口调用重试"""
return retry(
reraise=True,
stop=stop_after_attempt(3),
wait=wait_fixed(1),
retry=retry_if_exception_type(
(TimeoutException, ConnectError, HTTPStatusError)
),
)

View File

@ -7,6 +7,7 @@ import time
from typing import Any, ClassVar, Literal
import aiofiles
from anyio import EndOfStream
import httpx
from httpx import ConnectTimeout, HTTPStatusError, Response
from nonebot_plugin_alconna import UniMessage
@ -311,12 +312,17 @@ class AsyncHttpx:
completed=response.num_bytes_downloaded,
)
logger.info(
f"下载 {u} 成功.. "
f"Path{path.absolute()}"
f"下载 {u} 成功.. Path{path.absolute()}"
)
return True
except (TimeoutError, ConnectTimeout, HTTPStatusError):
logger.warning(f"下载 {u} 失败.. 尝试下一个地址..")
except EndOfStream as e:
logger.warning(
f"下载 {url} EndOfStream 异常 Path{path.absolute()}", e=e
)
if path.exists():
return True
logger.error(f"下载 {url} 下载超时.. Path{path.absolute()}")
except Exception as e:
logger.error(f"下载 {url} 错误 Path{path.absolute()}", e=e)