🐛 修复webui移除插件bug

This commit is contained in:
HibiKier 2025-08-12 16:58:31 +08:00
parent 977f0b13b3
commit 13dd68797c
2 changed files with 27 additions and 7 deletions

View File

@ -163,13 +163,17 @@ class StoreManager:
@classmethod
async def get_plugin_by_value(
cls, index_or_module: str, is_update: bool = False
cls,
index_or_module: str,
is_update: bool = False,
is_remove: bool = False,
) -> tuple[StorePluginInfo, bool]:
"""获取插件信息
参数:
index_or_module: 插件索引或模块名
is_update: 是否是更新插件
is_remove: 是否是移除插件
异常:
PluginStoreException: 插件不存在
@ -196,10 +200,22 @@ class StoreManager:
break
if not plugin_info:
raise PluginStoreException(f"插件不存在: {plugin_key}")
if not is_update and plugin_info.module in [p[0] for p in db_plugin_list]:
modules = [p[0] for p in db_plugin_list]
if is_remove:
if plugin_info.module not in modules:
raise PluginStoreException(f"插件 {plugin_info.name} 未安装,无法移除")
return plugin_info, is_external
if is_update:
if plugin_info.module not in modules:
raise PluginStoreException(f"插件 {plugin_info.name} 未安装,无法更新")
return plugin_info, is_external
if plugin_info.module in modules:
raise PluginStoreException(f"插件 {plugin_info.name} 已安装,无需重复安装")
if plugin_info.module not in [p[0] for p in db_plugin_list] and is_update:
raise PluginStoreException(f"插件 {plugin_info.name} 未安装,无法更新")
return plugin_info, is_external
@classmethod
@ -310,7 +326,7 @@ class StoreManager:
返回:
str: 返回消息
"""
plugin_info, _ = await cls.get_plugin_by_value(index_or_module)
plugin_info, _ = await cls.get_plugin_by_value(index_or_module, is_remove=True)
path = BASE_PATH
if plugin_info.github_url:
path = BASE_PATH / "plugins"

View File

@ -154,7 +154,10 @@ class RepoFileManager:
)
results.append((f, content))
except Exception as e:
logger.warning(f"获取阿里云文件内容失败: {file_path}", LOG_COMMAND, e=e)
if "code: 404" not in str(e):
logger.warning(
f"获取阿里云文件内容失败: {file_path}", LOG_COMMAND, e=e
)
if not ignore_error:
raise
logger.debug(f"获取阿里云文件内容: {[r[0] for r in results]}", LOG_COMMAND)
@ -526,7 +529,7 @@ class RepoFileManager:
content_bytes = content.encode("utf-8")
else:
content_bytes = content
logger.warning(f"写入文件: {local_path}")
logger.debug(f"写入文件: {local_path}")
async with aiofiles.open(local_path, "wb") as f:
await f.write(content_bytes)
result.success = True
@ -535,6 +538,7 @@ class RepoFileManager:
len(content.encode("utf-8") if isinstance(content, str) else content)
for _, content in file_contents
)
logger.info(f"下载文件成功: {[f[0] for f in file_contents]}")
return result
except Exception as e:
logger.error(f"下载文件失败: {e}")