mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-05 17:27:47 +00:00
- 移除原监控仪表盘独立模块,将相关功能合并到在线监控模块 - 重构租户配置字段名,统一使用logo_url和name替代tenant_logo/tenant_name - 优化搜索工具函数,移除重复导入 - 调整参数配置模型字段长度限制,移除config_value的max_length约束 - 清理冗余的常量定义和导入语句 - 修复批量状态设置接口的redis依赖注入 - 增强OAuth登录安全性,添加租户默认归属和state一次性消费 - 优化资源目录缓存逻辑,减少重复计算 - 新增API Token模块基础框架 - 完善用户token版本管理,支持主动失效JWT - 调整AI模型配置缓存过期时间 - 修复菜单类型字段索引,提升查询性能 - 简化前端刷新token调用逻辑 - 新增滑块验证完成接口和忘记密码验证码校验 - 调整系统配置默认值,添加操作日志保留天数和接口白名单配置 - 限制Mock支付回调仅在开发环境可用 - 重构websocket认证方式,支持更安全的subprotocol传参
67 lines
3.1 KiB
Python
67 lines
3.1 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Body, Depends, Query, Security
|
|
from fastapi.responses import JSONResponse
|
|
from fastapi_cache import FastAPICache
|
|
from fastapi_cache.decorator import cache
|
|
from redis.asyncio.client import Redis
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.common.request import PaginationService
|
|
from app.common.response import ResponseSchema, SuccessResponse
|
|
from app.core.base_schema import AuthSchema, PaginationQueryParam
|
|
from app.core.dependencies import AuthPermission, db_getter, get_current_user, redis_getter
|
|
from app.core.router_class import OperationLogRoute
|
|
|
|
from .schema import DashboardStatsSchema, OnlineOutSchema, OnlineQueryParam
|
|
from .service import OnlineService
|
|
|
|
OnlineRouter = APIRouter(route_class=OperationLogRoute, prefix="/online", tags=["在线用户"])
|
|
|
|
_STATS_NS = "online_stats"
|
|
|
|
|
|
@OnlineRouter.get("/list", summary="获取在线用户列表", response_model=ResponseSchema[list[OnlineOutSchema]], dependencies=[Security(AuthPermission(["module_monitor:online:query"]))])
|
|
async def get_online_list_controller(
|
|
redis: Annotated[Redis, Depends(redis_getter)],
|
|
page: Annotated[PaginationQueryParam, Query(description="分页参数")],
|
|
search: Annotated[OnlineQueryParam, Query(description="在线用户查询参数")],
|
|
) -> JSONResponse:
|
|
result_dict_list = await OnlineService.get_online_list(redis=redis, search=search)
|
|
result_dict = await PaginationService.paginate(
|
|
data_list=result_dict_list,
|
|
page_no=page.page_no,
|
|
page_size=page.page_size,
|
|
)
|
|
return SuccessResponse(data=result_dict, msg="获取成功")
|
|
|
|
|
|
@OnlineRouter.delete("/delete", summary="强制下线", response_model=ResponseSchema[None], dependencies=[Security(AuthPermission(["module_monitor:online:delete"]))])
|
|
async def delete_online_controller(
|
|
session_id: Annotated[str, Body(description="会话编号")],
|
|
redis: Annotated[Redis, Depends(redis_getter)],
|
|
) -> JSONResponse:
|
|
await OnlineService.delete_online(redis=redis, session_id=session_id)
|
|
await FastAPICache.clear(namespace=_STATS_NS)
|
|
return SuccessResponse(msg="强制下线成功")
|
|
|
|
|
|
@OnlineRouter.delete("/clear", summary="清除所有在线用户", response_model=ResponseSchema[None], dependencies=[Security(AuthPermission(["module_monitor:online:delete"]))])
|
|
async def clear_online_controller(
|
|
redis: Annotated[Redis, Depends(redis_getter)],
|
|
) -> JSONResponse:
|
|
await OnlineService.clear_online(redis=redis)
|
|
await FastAPICache.clear(namespace=_STATS_NS)
|
|
return SuccessResponse(msg="清除所有在线用户成功")
|
|
|
|
|
|
@OnlineRouter.get("/stats", summary="获取仪表盘统计数据", response_model=ResponseSchema[DashboardStatsSchema])
|
|
@cache(expire=15, namespace=_STATS_NS)
|
|
async def get_dashboard_stats_controller(
|
|
db: Annotated[AsyncSession, Depends(db_getter)],
|
|
redis: Annotated[Redis, Depends(redis_getter)],
|
|
_auth: Annotated[AuthSchema, Depends(get_current_user)],
|
|
) -> JSONResponse:
|
|
data = await OnlineService.get_dashboard_stats(db=db, redis=redis)
|
|
return SuccessResponse(data=data, msg="获取仪表盘统计成功")
|