mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 05:02:57 +00:00
refactor: 完成项目大规模代码重构与依赖清理
这是一次综合性的重构更新,包含以下主要变更: 1. 升级Python版本到3.12,更新依赖配置 2. 替换旧的.j2模板为.jinja2格式,新增代码生成模板 3. 重构权限过滤策略,更新权限枚举与模型配置 4. 移除Prefect依赖,替换为自研拓扑并行执行引擎 5. 重构认证与上下文管理,拆分租户/请求上下文 6. 简化响应模型、CRUD与服务层代码 7. 清理废弃的支付网关模块,重构订单定时任务 8. 更新在线用户、监控等模块的接口与路由 9. 优化邮件模板与工具类,新增邮件模板文件 10. 修复数据库会话配置与类型提示
This commit is contained in:
@@ -20,12 +20,10 @@ from .schema import (
|
||||
)
|
||||
from .service import PluginService
|
||||
|
||||
PluginRouter = APIRouter(route_class=OperationLogRoute, prefix="/plugin", tags=["插件管理"])
|
||||
PluginRouter = APIRouter(route_class=OperationLogRoute, prefix="/plugin", tags=["平台管理", "插件管理"])
|
||||
|
||||
_PLUGIN_NS = "plugin"
|
||||
|
||||
# ───── 超管:插件 CRUD ─────
|
||||
|
||||
|
||||
@PluginRouter.get(
|
||||
"/list",
|
||||
@@ -38,19 +36,7 @@ async def plugin_list_controller(
|
||||
search: Annotated[PluginQueryParam, Depends()],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:query"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
插件列表
|
||||
|
||||
参数:
|
||||
- page (PaginationQueryParam): 分页查询参数。
|
||||
- search (PluginQueryParam): 查询筛选参数。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 包含分页插件列表的 JSON 响应。
|
||||
"""
|
||||
r = await PluginService.page_service(
|
||||
auth=auth,
|
||||
r = await PluginService(auth).page(
|
||||
page_no=page.page_no,
|
||||
page_size=page.page_size,
|
||||
search=search,
|
||||
@@ -68,17 +54,7 @@ async def plugin_detail_controller(
|
||||
id: Annotated[int, Path()],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:query"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
插件详情
|
||||
|
||||
参数:
|
||||
- id (int): 插件 ID。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 包含插件详情的 JSON 响应。
|
||||
"""
|
||||
return SuccessResponse(data=await PluginService.detail_service(auth=auth, id=id), msg="查询成功")
|
||||
return SuccessResponse(data=await PluginService(auth).detail(id=id), msg="查询成功")
|
||||
|
||||
|
||||
@PluginRouter.post(
|
||||
@@ -90,17 +66,7 @@ async def plugin_create_controller(
|
||||
data: PluginCreateSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:create"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
创建插件
|
||||
|
||||
参数:
|
||||
- data (PluginCreateSchema): 插件创建参数。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 包含创建后的插件详情的 JSON 响应。
|
||||
"""
|
||||
r = await PluginService.create_service(auth=auth, data=data)
|
||||
r = await PluginService(auth).create(data=data)
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
return SuccessResponse(data=r, msg="创建成功")
|
||||
|
||||
@@ -115,18 +81,7 @@ async def plugin_update_controller(
|
||||
data: PluginUpdateSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:update"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
更新插件
|
||||
|
||||
参数:
|
||||
- id (int): 插件 ID。
|
||||
- data (PluginUpdateSchema): 插件更新参数。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 包含更新后的插件详情的 JSON 响应。
|
||||
"""
|
||||
r = await PluginService.update_service(auth=auth, id=id, data=data)
|
||||
r = await PluginService(auth).update(id=id, data=data)
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
return SuccessResponse(data=r, msg="更新成功")
|
||||
|
||||
@@ -140,24 +95,11 @@ async def plugin_delete_controller(
|
||||
ids: Annotated[list[int], Body()],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:delete"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
删除插件
|
||||
|
||||
参数:
|
||||
- ids (list[int]): 插件 ID 列表。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 删除结果。
|
||||
"""
|
||||
await PluginService.delete_service(auth=auth, ids=ids)
|
||||
await PluginService(auth).delete(ids=ids)
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
return SuccessResponse(msg="删除成功")
|
||||
|
||||
|
||||
# ───── 租户:插件市场 ─────
|
||||
|
||||
|
||||
@PluginRouter.get(
|
||||
"/marketplace",
|
||||
summary="插件市场",
|
||||
@@ -169,18 +111,7 @@ async def plugin_marketplace_controller(
|
||||
page: Annotated[PaginationQueryParam, Depends()],
|
||||
category: Annotated[str | None, Query(description="分类筛选")] = None,
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
插件市场
|
||||
|
||||
参数:
|
||||
- page (PaginationQueryParam): 分页查询参数。
|
||||
- category (str | None): 分类筛选。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 包含分页市场插件列表的 JSON 响应。
|
||||
"""
|
||||
r = await PluginService.marketplace_service(auth=auth, page_no=page.page_no, page_size=page.page_size, category=category)
|
||||
r = await PluginService(auth).marketplace(page_no=page.page_no, page_size=page.page_size, category=category)
|
||||
return SuccessResponse(data=r, msg="查询成功")
|
||||
|
||||
|
||||
@@ -193,17 +124,7 @@ async def plugin_install_controller(
|
||||
data: PluginInstallSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:install"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
安装插件
|
||||
|
||||
参数:
|
||||
- data (PluginInstallSchema): 安装参数(插件 ID)。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 安装结果。
|
||||
"""
|
||||
await PluginService.install_service(auth=auth, plugin_id=data.plugin_id)
|
||||
await PluginService(auth).install(plugin_id=data.plugin_id)
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
return SuccessResponse(msg="安装成功")
|
||||
|
||||
@@ -217,17 +138,7 @@ async def plugin_uninstall_controller(
|
||||
data: PluginInstallSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:uninstall"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
卸载插件
|
||||
|
||||
参数:
|
||||
- data (PluginInstallSchema): 卸载参数(插件 ID)。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 卸载结果。
|
||||
"""
|
||||
await PluginService.uninstall_service(auth=auth, plugin_id=data.plugin_id)
|
||||
await PluginService(auth).uninstall(plugin_id=data.plugin_id)
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
return SuccessResponse(msg="卸载成功")
|
||||
|
||||
@@ -241,17 +152,7 @@ async def plugin_toggle_controller(
|
||||
data: PluginInstallSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:toggle"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
启用/禁用插件
|
||||
|
||||
参数:
|
||||
- data (PluginInstallSchema): 操作参数(插件 ID)。
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 操作结果。
|
||||
"""
|
||||
await PluginService.toggle_service(auth=auth, plugin_id=data.plugin_id)
|
||||
await PluginService(auth).toggle(plugin_id=data.plugin_id)
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
return SuccessResponse(msg="操作成功")
|
||||
|
||||
@@ -265,16 +166,7 @@ async def plugin_toggle_controller(
|
||||
async def plugin_my_list_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:query"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
我的插件
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 包含已安装插件列表的 JSON 响应。
|
||||
"""
|
||||
return SuccessResponse(data=await PluginService.my_plugins_service(auth=auth), msg="查询成功")
|
||||
return SuccessResponse(data=await PluginService(auth).my_plugins(), msg="查询成功")
|
||||
|
||||
|
||||
@PluginRouter.post(
|
||||
@@ -285,18 +177,6 @@ async def plugin_my_list_controller(
|
||||
async def plugin_reload_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:reload"]))],
|
||||
) -> JSONResponse:
|
||||
"""
|
||||
热重载插件路由(管理员)。
|
||||
|
||||
重新扫描 app/plugin/module_* 目录,清除模块缓存并注册新路由,
|
||||
无需重启服务器。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型。
|
||||
|
||||
返回:
|
||||
- JSONResponse: 包含重载结果的 JSON 响应。
|
||||
"""
|
||||
msg = PluginService.reload_service()
|
||||
msg = PluginService.reload()
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
return SuccessResponse(data=msg, msg="重载成功")
|
||||
|
||||
Reference in New Issue
Block a user