diff --git a/nb_cli_plugin_webui/app/store/constants.py b/nb_cli_plugin_webui/app/store/constants.py index 005833a..532f834 100644 --- a/nb_cli_plugin_webui/app/store/constants.py +++ b/nb_cli_plugin_webui/app/store/constants.py @@ -1,3 +1,4 @@ class ErrorCode: MODULE_TYPE_NOT_FOUND = "模块类型未找到" MODULE_IS_EXISTED = "模块已存在" + MODULE_NOT_FOUND = "模块未找到" diff --git a/nb_cli_plugin_webui/app/store/exception.py b/nb_cli_plugin_webui/app/store/exception.py index a2a2a55..cd62866 100644 --- a/nb_cli_plugin_webui/app/store/exception.py +++ b/nb_cli_plugin_webui/app/store/exception.py @@ -9,3 +9,7 @@ class ModuleTypeNotFound(NotFound): class ModuleIsExisted(NotFound): detail = ErrorCode.MODULE_IS_EXISTED + + +class ModuleNotFound(NotFound): + detail = ErrorCode.MODULE_NOT_FOUND diff --git a/nb_cli_plugin_webui/app/store/service.py b/nb_cli_plugin_webui/app/store/service.py index 2c0a5f4..a8f40af 100644 --- a/nb_cli_plugin_webui/app/store/service.py +++ b/nb_cli_plugin_webui/app/store/service.py @@ -18,7 +18,7 @@ ) from .schemas import Plugin, ModuleInfo -from .exception import ModuleIsExisted, ModuleTypeNotFound +from .exception import ModuleNotFound, ModuleIsExisted, ModuleTypeNotFound def install_nonebot_module( @@ -92,6 +92,23 @@ async def uninstall_nonebot_module( env: str, module: Annotated[Union[ModuleInfo, Plugin], Field(discriminator="module_type")], ) -> None: + if isinstance(module, Plugin): + for plugin in project.read().plugins: + if module.module_name == plugin.module_name: + break + else: + raise ModuleNotFound() + elif isinstance(module, ModuleInfo): + for adapter in project.read().adapters: + if module.module_name == adapter.module_name: + break + else: + for driver in project.read().drivers: + if module.module_name == driver.module_name: + break + else: + raise ModuleNotFound() + async def _call_pip_uninstall(package) -> None: proc = await call_pip_uninstall( package,