Skip to content

Commit

Permalink
🐛 修复拓展商店移除拓展时后端实现未检查是否存在
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyomotoi committed Dec 5, 2023
1 parent d43f513 commit 8d5859e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions nb_cli_plugin_webui/app/store/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class ErrorCode:
MODULE_TYPE_NOT_FOUND = "模块类型未找到"
MODULE_IS_EXISTED = "模块已存在"
MODULE_NOT_FOUND = "模块未找到"
4 changes: 4 additions & 0 deletions nb_cli_plugin_webui/app/store/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ class ModuleTypeNotFound(NotFound):

class ModuleIsExisted(NotFound):
detail = ErrorCode.MODULE_IS_EXISTED


class ModuleNotFound(NotFound):
detail = ErrorCode.MODULE_NOT_FOUND
19 changes: 18 additions & 1 deletion nb_cli_plugin_webui/app/store/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)

from .schemas import Plugin, ModuleInfo
from .exception import ModuleIsExisted, ModuleTypeNotFound
from .exception import ModuleNotFound, ModuleIsExisted, ModuleTypeNotFound


def install_nonebot_module(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8d5859e

Please sign in to comment.