feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -247,3 +247,15 @@ Deno.test('invalid input is rejected before reserving quota', async () => {
|
|||
assertEquals(response.status, 415, 'unsupported type')
|
||||
assertEquals(h.events, [], 'no quota or provider work')
|
||||
})
|
||||
|
||||
Deno.test('non-multipart body fails closed with 400 instead of 500', async () => {
|
||||
const h = harness([fakeProvider('groq', OK)])
|
||||
const response = await h.handler(new Request('http://localhost/stt-proxy', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: '{"audio":1}',
|
||||
}))
|
||||
assertEquals(response.status, 400, 'status')
|
||||
assertEquals(await response.json(), { error: 'invalid_multipart_body' }, 'body')
|
||||
assertEquals(h.events, [], 'no quota or provider work')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
// "no speech" result: it is never retried on the next paid provider and is answered
|
||||
// with a fixed `stt_no_speech` code (clients reject a 200 with an empty transcript).
|
||||
|
||||
import { corsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
|
||||
import { handleCorsPreflightRequest } from '../_shared/cors.ts'
|
||||
import { createStatusJsonResponder } from '../_shared/json-response.ts'
|
||||
import {
|
||||
type DictionaryHints,
|
||||
type NormalizedSttResult,
|
||||
|
|
@ -116,12 +117,7 @@ export async function runSttChain(
|
|||
return { kind: 'failed', billed, unavailable, attempts }
|
||||
}
|
||||
|
||||
function json(status: number, payload: unknown): Response {
|
||||
return new Response(JSON.stringify(payload), {
|
||||
status,
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
const json = createStatusJsonResponder()
|
||||
|
||||
export function createSttProxyHandler(deps: SttProxyDeps): (req: Request) => Promise<Response> {
|
||||
const { quota, logger } = deps
|
||||
|
|
@ -142,7 +138,12 @@ export function createSttProxyHandler(deps: SttProxyDeps): (req: Request) => Pro
|
|||
const user = auth.user
|
||||
|
||||
// 2) input
|
||||
const formData = await req.formData()
|
||||
let formData: FormData
|
||||
try {
|
||||
formData = await req.formData()
|
||||
} catch {
|
||||
return json(400, { error: 'invalid_multipart_body' })
|
||||
}
|
||||
const audio = formData.get('audio') ?? formData.get('file')
|
||||
const languageCode = String(formData.get('language_code') ?? 'ko')
|
||||
if (!(audio instanceof Blob)) return json(400, { error: 'Missing audio field' })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue