Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/app/admin/api/v1/sys/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
12 changes: 7 additions & 5 deletions backend/app/admin/service/plugin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion backend/plugin/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down