- 支持 MiniMax/OpenAI/Google Gemini/智谱/Kimi 五个平台 - 插件化 Provider 架构,自动发现注册 - 多维度 QuotaRule 额度追踪(固定间隔/自然周期/API同步/手动) - OpenAI + Anthropic 兼容 API 代理,SSE 流式转发 - Model 路由表 + 额度耗尽自动 fallback - 多媒体任务队列(图片/语音/视频) - Vue3 + Tailwind 单文件 Web 仪表盘 - Docker 一键部署 Made-with: Cursor
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""额度查询 API"""
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from app import database as db
|
|
from app.models import DashboardPlan
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/dashboard", response_model=list[DashboardPlan])
|
|
async def dashboard_overview():
|
|
"""仪表盘总览: 所有 Plan 及其 QuotaRule 状态"""
|
|
plans = await db.list_plans()
|
|
result = []
|
|
for p in plans:
|
|
rules = await db.list_quota_rules(p["id"])
|
|
all_ok = all(
|
|
r["quota_used"] < r["quota_total"]
|
|
for r in rules if r["enabled"]
|
|
)
|
|
result.append({
|
|
"id": p["id"],
|
|
"name": p["name"],
|
|
"provider_name": p["provider_name"],
|
|
"plan_type": p["plan_type"],
|
|
"enabled": p["enabled"],
|
|
"quota_rules": rules,
|
|
"all_available": all_ok and p["enabled"],
|
|
})
|
|
return result
|
|
|
|
|
|
@router.get("/plan/{plan_id}/available")
|
|
async def check_available(plan_id: str):
|
|
"""检查 Plan 当前是否可用"""
|
|
available = await db.check_plan_available(plan_id)
|
|
return {"plan_id": plan_id, "available": available}
|
|
|
|
|
|
@router.post("/plan/{plan_id}/refresh")
|
|
async def manual_refresh(plan_id: str, rule_id: str | None = None):
|
|
"""手动重置额度"""
|
|
rules = await db.list_quota_rules(plan_id)
|
|
count = 0
|
|
for r in rules:
|
|
if rule_id and r["id"] != rule_id:
|
|
continue
|
|
await db.update_quota_rule(r["id"], quota_used=0)
|
|
count += 1
|
|
return {"reset_count": count}
|