mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🐛 修复webui移除插件bug
This commit is contained in:
parent
977f0b13b3
commit
13dd68797c
@ -163,13 +163,17 @@ class StoreManager:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_plugin_by_value(
|
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]:
|
) -> tuple[StorePluginInfo, bool]:
|
||||||
"""获取插件信息
|
"""获取插件信息
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
index_or_module: 插件索引或模块名
|
index_or_module: 插件索引或模块名
|
||||||
is_update: 是否是更新插件
|
is_update: 是否是更新插件
|
||||||
|
is_remove: 是否是移除插件
|
||||||
|
|
||||||
异常:
|
异常:
|
||||||
PluginStoreException: 插件不存在
|
PluginStoreException: 插件不存在
|
||||||
@ -196,12 +200,24 @@ class StoreManager:
|
|||||||
break
|
break
|
||||||
if not plugin_info:
|
if not plugin_info:
|
||||||
raise PluginStoreException(f"插件不存在: {plugin_key}")
|
raise PluginStoreException(f"插件不存在: {plugin_key}")
|
||||||
if not is_update and plugin_info.module in [p[0] for p in db_plugin_list]:
|
|
||||||
raise PluginStoreException(f"插件 {plugin_info.name} 已安装,无需重复安装")
|
modules = [p[0] for p in db_plugin_list]
|
||||||
if plugin_info.module not in [p[0] for p in db_plugin_list] and is_update:
|
|
||||||
|
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} 未安装,无法更新")
|
raise PluginStoreException(f"插件 {plugin_info.name} 未安装,无法更新")
|
||||||
return plugin_info, is_external
|
return plugin_info, is_external
|
||||||
|
|
||||||
|
if plugin_info.module in modules:
|
||||||
|
raise PluginStoreException(f"插件 {plugin_info.name} 已安装,无需重复安装")
|
||||||
|
|
||||||
|
return plugin_info, is_external
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def add_plugin(cls, index_or_module: str) -> str:
|
async def add_plugin(cls, index_or_module: str) -> str:
|
||||||
"""添加插件
|
"""添加插件
|
||||||
@ -310,7 +326,7 @@ class StoreManager:
|
|||||||
返回:
|
返回:
|
||||||
str: 返回消息
|
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
|
path = BASE_PATH
|
||||||
if plugin_info.github_url:
|
if plugin_info.github_url:
|
||||||
path = BASE_PATH / "plugins"
|
path = BASE_PATH / "plugins"
|
||||||
|
|||||||
@ -154,7 +154,10 @@ class RepoFileManager:
|
|||||||
)
|
)
|
||||||
results.append((f, content))
|
results.append((f, content))
|
||||||
except Exception as e:
|
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:
|
if not ignore_error:
|
||||||
raise
|
raise
|
||||||
logger.debug(f"获取阿里云文件内容: {[r[0] for r in results]}", LOG_COMMAND)
|
logger.debug(f"获取阿里云文件内容: {[r[0] for r in results]}", LOG_COMMAND)
|
||||||
@ -526,7 +529,7 @@ class RepoFileManager:
|
|||||||
content_bytes = content.encode("utf-8")
|
content_bytes = content.encode("utf-8")
|
||||||
else:
|
else:
|
||||||
content_bytes = content
|
content_bytes = content
|
||||||
logger.warning(f"写入文件: {local_path}")
|
logger.debug(f"写入文件: {local_path}")
|
||||||
async with aiofiles.open(local_path, "wb") as f:
|
async with aiofiles.open(local_path, "wb") as f:
|
||||||
await f.write(content_bytes)
|
await f.write(content_bytes)
|
||||||
result.success = True
|
result.success = True
|
||||||
@ -535,6 +538,7 @@ class RepoFileManager:
|
|||||||
len(content.encode("utf-8") if isinstance(content, str) else content)
|
len(content.encode("utf-8") if isinstance(content, str) else content)
|
||||||
for _, content in file_contents
|
for _, content in file_contents
|
||||||
)
|
)
|
||||||
|
logger.info(f"下载文件成功: {[f[0] for f in file_contents]}")
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"下载文件失败: {e}")
|
logger.error(f"下载文件失败: {e}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user