fix: 三端联调测试 2 P1 + 2 P2 + 4 P3 修复

P1-07: billing get_or_create_usage 同步 max_* 列到当前计划限额
P1-08: relay handler 增加直接配额检查 (relay_requests/input/output_tokens)
P2-09: relay failover 成功后记录 tokens 并标记 completed
P2-10: Tauri agentStore saas-relay 模式下从 SaaS API 获取真实用量
P2-14: super_admin 合成 subscription + check_quota 放行
P3-19: 新建 ApiKeys.tsx 页面替代 ModelServices 路由
P3-15: antd destroyOnClose → destroyOnHidden (3处)
P3-16: ProTable onSearch → onSubmit (2处)
This commit is contained in:
iven
2026-04-14 17:48:22 +08:00
parent 45fd9fee7b
commit dd854479eb
11 changed files with 259 additions and 12 deletions

View File

@@ -23,6 +23,18 @@ pub async fn chat_completions(
) -> SaasResult<Response> {
check_permission(&ctx, "relay:use")?;
// P1-08 修复: 直接配额检查(不依赖中间件,防御性编程)
for quota_type in &["relay_requests", "input_tokens", "output_tokens"] {
let check = crate::billing::service::check_quota(
&state.db, &ctx.account_id, &ctx.role, quota_type,
).await?;
if !check.allowed {
return Err(SaasError::RateLimited(
check.reason.unwrap_or_else(|| format!("{} 配额已用尽", quota_type))
));
}
}
// 队列容量检查:使用内存 AtomicI64 计数器,消除 DB COUNT 查询
let max_queue_size = {
let config = state.config.read().await;