"""Feishu long-connection routes.""" from __future__ import annotations from fastapi import APIRouter, Depends, HTTPException from ...dependencies.auth import get_current_user from ...models import User from ...services.auth import has_any_role from ...services.feishu_long_connection import get_feishu_long_connection_manager router = APIRouter() @router.get("/long-connection/status") async def feishu_long_connection_status( current_user: User = Depends(get_current_user), ): """查询飞书长连接状态。""" _ = current_user manager = get_feishu_long_connection_manager() if not manager: return { "status": "error", "message": "Feishu 长连接管理器未初始化", "mode": "long_connection", "data": None, } return { "status": "success", "mode": "long_connection", "data": manager.status(), } @router.post("/long-connection/restart") async def restart_feishu_long_connection( current_user: User = Depends(get_current_user), ): """手动重启飞书长连接。""" if not has_any_role(str(current_user.role or ""), ["ADMIN", "BOSS"]): raise HTTPException(status_code=403, detail="只有管理员可以重启飞书长连接") manager = get_feishu_long_connection_manager() if not manager: raise HTTPException(status_code=500, detail="Feishu 长连接管理器未初始化") await manager.restart() return { "status": "success", "message": "Feishu 长连接已重启", "mode": "long_connection", "data": manager.status(), }