diff --git a/backend/app/admin/api/v1/sys/plugin.py b/backend/app/admin/api/v1/sys/plugin.py index 1c9886f8..9c5012c3 100644 --- a/backend/app/admin/api/v1/sys/plugin.py +++ b/backend/app/admin/api/v1/sys/plugin.py @@ -22,9 +22,9 @@ async def get_all_plugins() -> ResponseSchemaModel[list[dict[str, Any]]]: return response_base.success(data=plugins) -@router.get('/new', summary='是否存在新插件', dependencies=[DependsJwtAuth]) -async def has_new_plugins() -> ResponseSchemaModel[bool]: - plugins = await plugin_service.has_new() +@router.get('/changed', summary='插件状态是否变更', dependencies=[DependsJwtAuth]) +async def plugin_changed() -> ResponseSchemaModel[bool]: + plugins = await plugin_service.changed() return response_base.success(data=bool(plugins)) diff --git a/backend/app/admin/service/plugin_service.py b/backend/app/admin/service/plugin_service.py index b0074fda..b2f28a28 100644 --- a/backend/app/admin/service/plugin_service.py +++ b/backend/app/admin/service/plugin_service.py @@ -40,9 +40,9 @@ async def get_all() -> list[dict[str, Any]]: return result @staticmethod - async def has_new() -> str | None: - """是否存在新插件""" - return await redis_client.get(f'{settings.PLUGIN_REDIS_PREFIX}:new') + async def changed() -> str | None: + """插件状态是否变更""" + return await redis_client.get(f'{settings.PLUGIN_REDIS_PREFIX}:changed') @staticmethod async def install_zip(*, file: UploadFile) -> None: @@ -94,7 +94,7 @@ async def install_zip(*, file: UploadFile) -> None: zf.extractall(os.path.join(PLUGIN_DIR, plugin_name), members) await install_requirements_async(plugin_name) - await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:new', 'ture') + await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture') @staticmethod async def install_git(*, repo_url: str): @@ -118,7 +118,7 @@ async def install_git(*, repo_url: str): raise errors.ServerError(msg='插件安装失败,请稍后重试') from e else: await install_requirements_async(repo_name) - await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:new', 'ture') + await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture') @staticmethod async def uninstall(*, plugin: str): @@ -135,6 +135,8 @@ async def uninstall(*, plugin: str): bacup_dir = os.path.join(PLUGIN_DIR, f'{plugin}.{timezone.now().strftime("%Y%m%d%H%M%S")}.backup') shutil.move(plugin_dir, bacup_dir) await redis_client.delete(f'{settings.PLUGIN_REDIS_PREFIX}:info:{plugin}') + await redis_client.hdel(f'{settings.PLUGIN_REDIS_PREFIX}:status', plugin) + await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture') @staticmethod async def update_status(*, plugin: str): diff --git a/backend/plugin/tools.py b/backend/plugin/tools.py index 6d24d32b..2daf57ab 100644 --- a/backend/plugin/tools.py +++ b/backend/plugin/tools.py @@ -129,7 +129,7 @@ def parse_plugin_config() -> tuple[list[dict[str, Any]], list[dict[str, Any]]]: # 缓存插件状态 loop.create_task(redis_client.hset(f'{settings.PLUGIN_REDIS_PREFIX}:status', mapping=plugin_status)) # type: ignore - loop.create_task(redis_client.delete(f'{settings.PLUGIN_REDIS_PREFIX}:new')) + loop.create_task(redis_client.delete(f'{settings.PLUGIN_REDIS_PREFIX}:changed')) return extra_plugins, app_plugins