52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from typing import Any, List
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from app import schemas
|
|
from app.core.plugin import PluginManager
|
|
from app.db.models.user import User
|
|
from app.db.systemconfig_oper import SystemConfigOper
|
|
from app.db.userauth import get_current_active_user
|
|
from app.schemas.types import SystemConfigKey
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/", summary="所有插件", response_model=List[schemas.Plugin])
|
|
async def all_plugins(_: User = Depends(get_current_active_user)) -> Any:
|
|
"""
|
|
查询所有插件清单
|
|
"""
|
|
return PluginManager().get_plugin_apps()
|
|
|
|
|
|
@router.get("/installed", summary="已安装插件", response_model=List[str])
|
|
async def installed_plugins(_: User = Depends(get_current_active_user)) -> Any:
|
|
"""
|
|
查询用户已安装插件清单
|
|
"""
|
|
return SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
|
|
|
|
|
|
@router.get("/{plugin_id}", summary="获取插件配置")
|
|
async def plugin_config(plugin_id: str, _: User = Depends(get_current_active_user)) -> dict:
|
|
"""
|
|
根据插件ID获取插件配置信息
|
|
"""
|
|
return PluginManager().get_plugin_config(plugin_id)
|
|
|
|
|
|
@router.put("/{plugin_id}", summary="更新插件配置", response_model=schemas.Response)
|
|
async def set_plugin_config(plugin_id: str, conf: dict,
|
|
_: User = Depends(get_current_active_user)) -> Any:
|
|
"""
|
|
根据插件ID获取插件配置信息
|
|
"""
|
|
PluginManager().save_plugin_config(plugin_id, conf)
|
|
return schemas.Response(success=True)
|
|
|
|
|
|
# 注册插件API
|
|
for api in PluginManager().get_plugin_apis():
|
|
router.add_api_route(**api)
|