Skip to content

Commit 85b0294

Browse files
authored
Update the new plugin status to changed (#607)
* Fix cache update after plugin uninstall * Update new to changed
1 parent a8ecb4a commit 85b0294

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

backend/app/admin/api/v1/sys/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ async def get_all_plugins() -> ResponseSchemaModel[list[dict[str, Any]]]:
2222
return response_base.success(data=plugins)
2323

2424

25-
@router.get('/new', summary='是否存在新插件', dependencies=[DependsJwtAuth])
26-
async def has_new_plugins() -> ResponseSchemaModel[bool]:
27-
plugins = await plugin_service.has_new()
25+
@router.get('/changed', summary='插件状态是否变更', dependencies=[DependsJwtAuth])
26+
async def plugin_changed() -> ResponseSchemaModel[bool]:
27+
plugins = await plugin_service.changed()
2828
return response_base.success(data=bool(plugins))
2929

3030

backend/app/admin/service/plugin_service.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ async def get_all() -> list[dict[str, Any]]:
4040
return result
4141

4242
@staticmethod
43-
async def has_new() -> str | None:
44-
"""是否存在新插件"""
45-
return await redis_client.get(f'{settings.PLUGIN_REDIS_PREFIX}:new')
43+
async def changed() -> str | None:
44+
"""插件状态是否变更"""
45+
return await redis_client.get(f'{settings.PLUGIN_REDIS_PREFIX}:changed')
4646

4747
@staticmethod
4848
async def install_zip(*, file: UploadFile) -> None:
@@ -94,7 +94,7 @@ async def install_zip(*, file: UploadFile) -> None:
9494
zf.extractall(os.path.join(PLUGIN_DIR, plugin_name), members)
9595

9696
await install_requirements_async(plugin_name)
97-
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:new', 'ture')
97+
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture')
9898

9999
@staticmethod
100100
async def install_git(*, repo_url: str):
@@ -118,7 +118,7 @@ async def install_git(*, repo_url: str):
118118
raise errors.ServerError(msg='插件安装失败,请稍后重试') from e
119119
else:
120120
await install_requirements_async(repo_name)
121-
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:new', 'ture')
121+
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture')
122122

123123
@staticmethod
124124
async def uninstall(*, plugin: str):
@@ -135,6 +135,8 @@ async def uninstall(*, plugin: str):
135135
bacup_dir = os.path.join(PLUGIN_DIR, f'{plugin}.{timezone.now().strftime("%Y%m%d%H%M%S")}.backup')
136136
shutil.move(plugin_dir, bacup_dir)
137137
await redis_client.delete(f'{settings.PLUGIN_REDIS_PREFIX}:info:{plugin}')
138+
await redis_client.hdel(f'{settings.PLUGIN_REDIS_PREFIX}:status', plugin)
139+
await redis_client.set(f'{settings.PLUGIN_REDIS_PREFIX}:changed', 'ture')
138140

139141
@staticmethod
140142
async def update_status(*, plugin: str):

backend/plugin/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def parse_plugin_config() -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
129129

130130
# 缓存插件状态
131131
loop.create_task(redis_client.hset(f'{settings.PLUGIN_REDIS_PREFIX}:status', mapping=plugin_status)) # type: ignore
132-
loop.create_task(redis_client.delete(f'{settings.PLUGIN_REDIS_PREFIX}:new'))
132+
loop.create_task(redis_client.delete(f'{settings.PLUGIN_REDIS_PREFIX}:changed'))
133133

134134
return extra_plugins, app_plugins
135135

0 commit comments

Comments
 (0)