fix(quotas): unifier le décompte IA (BYOK, rollback) et combler les fuites
Centralise la réserve via ai-quota, corrige admin unavailable (-1), brancher les routes sans quota et le host-pays brainstorm, avec usage-meter élargi, noms de clusters, MCP et ajustements dashboard/insights. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getMobileUserId } from '@/lib/mobile-auth'
|
||||
import { getSystemConfig } from '@/lib/config'
|
||||
import { reserveUsageOrThrow, QuotaExceededError } from '@/lib/entitlements'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const userId = await getMobileUserId(req)
|
||||
@@ -18,6 +19,15 @@ export async function POST(req: NextRequest) {
|
||||
const apiKey = config.OPENAI_API_KEY
|
||||
if (!apiKey) return NextResponse.json({ error: 'Service non disponible' }, { status: 503 })
|
||||
|
||||
try {
|
||||
await reserveUsageOrThrow(userId, 'voice_transcribe')
|
||||
} catch (err) {
|
||||
if (err instanceof QuotaExceededError) {
|
||||
return NextResponse.json(err.toJSON(), { status: 429 })
|
||||
}
|
||||
throw err
|
||||
}
|
||||
|
||||
const whisperForm = new FormData()
|
||||
whisperForm.append('file', file, 'audio.m4a')
|
||||
whisperForm.append('model', 'whisper-1')
|
||||
|
||||
Reference in New Issue
Block a user