feat(compute): 新增 /admin/compute/proxy/{path} 透传 compute-engine 管理 API
- compute_client.proxy(): 转发到引擎 /api/<path>,保留原始状态码/响应体 - rbac_operator 新增 compute_proxy 端点(GET/POST/PUT/DELETE/PATCH),运营端鉴权 - 使 admin 端可 1:1 驱动 new-api 完整管理面(models/channels/groups/tokens/users/logs/redemption/ratio)
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
import json
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..dependencies import get_db
|
||||
@@ -212,6 +214,32 @@ async def compute_provision(
|
||||
)
|
||||
|
||||
|
||||
@router.api_route(
|
||||
"/compute/proxy/{path:path}",
|
||||
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
|
||||
response_class=Response,
|
||||
summary="算力中心管理 API 透传(对齐 compute-engine /api/*)",
|
||||
)
|
||||
async def compute_proxy(path: str, request: Request, _u: dict = Depends(require_roles("operator"))):
|
||||
"""算力中心管理转发:把 admin 端请求 1:1 透传到 compute-engine(new-api) 管理 API ``/api/{path}``。
|
||||
|
||||
打通全部管理面(models / channels / groups / tokens / users / logs / redemption / ratio /
|
||||
system-settings 等),保留引擎原始状态码与响应体,使 admin 端可作为 new-api 唯一管理 UI。
|
||||
"""
|
||||
body = await request.body()
|
||||
json_body = None
|
||||
if body and request.headers.get("content-type", "").startswith("application/json"):
|
||||
try:
|
||||
json_body = json.loads(body)
|
||||
except Exception: # noqa: BLE001
|
||||
json_body = None
|
||||
params = dict(request.query_params)
|
||||
result = await compute_client.proxy(
|
||||
request.method, "/" + path, json_body=json_body, params=params,
|
||||
)
|
||||
return Response(content=result["body"], status_code=int(result["status"]), media_type="application/json")
|
||||
|
||||
|
||||
# ── 培训业务 · 课程(桥接 app.training courses 表)─────────────────────────
|
||||
@router.get("/courses", summary="课程列表")
|
||||
async def list_courses(
|
||||
|
||||
Reference in New Issue
Block a user