Usability and test infrastructure updates.
This commit is contained in:
1 parent
99b1732003
commit
7040f031a6
12 files changed
+549
-127
No files matched your search
+20
-7
@@ -1,10 +1,11 @@
|
||||
import { serve } from "bun";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, normalize, sep } from "node:path";
|
||||
import { ensureIcons, ICONS_DIR } from "../scripts/generate-icons.ts";
|
||||
import { injectPrecacheManifest } from "./pwa/precache.ts";
|
||||
import { auth } from "./server/auth.ts";
|
||||
import { AUTH_ENABLED } from "./server/flags.ts";
|
||||
import { MAX_UPLOAD_BYTES, transcribe } from "./server/transcribe.ts";
|
||||
import { MAX_UPLOAD_BYTES, parseLanguageAndTask, sidecar, transcribe } from "./server/transcribe.ts";
|
||||
import { liveWebSocket } from "./server/live.ts";
|
||||
import { getFasterWhisperModel } from "./lib/models.ts";
|
||||
|
||||
@@ -132,15 +133,27 @@ async function handleApiRequest(request: Request, server: any): Promise<Response
|
||||
if (!modelId) return new Response("Missing model", { status: 400 });
|
||||
const fasterWhisperModel = getFasterWhisperModel(modelId);
|
||||
if (!fasterWhisperModel) return new Response("Unknown model", { status: 400 });
|
||||
|
||||
// Same validation as POST /api/transcribe (D-030-adjacent: never forward
|
||||
// an unvalidated task/language string into the sidecar protocol just
|
||||
// because this entry point is a WebSocket, not JSON over HTTP).
|
||||
const options = parseLanguageAndTask(url);
|
||||
if (typeof options === "string") return new Response(options, { status: 400 });
|
||||
// Fail fast like the HTTP route (D-013 "degrade gracefully") instead of
|
||||
// opening a socket that can only report unavailability once the first
|
||||
// segment reaches the sidecar.
|
||||
const status = await sidecar.status();
|
||||
if (!status.available) {
|
||||
return new Response(status.reason ?? "server engine unavailable", { status: 503 });
|
||||
}
|
||||
|
||||
const success = server.upgrade(request, {
|
||||
data: {
|
||||
user,
|
||||
model: fasterWhisperModel,
|
||||
language: url.searchParams.get("language") || undefined,
|
||||
task: url.searchParams.get("task") || undefined,
|
||||
tempDir: require("node:os").tmpdir()
|
||||
}
|
||||
language: options.language,
|
||||
task: options.task,
|
||||
tempDir: tmpdir(),
|
||||
},
|
||||
});
|
||||
if (success) return undefined;
|
||||
return new Response("WebSocket upgrade failed", { status: 500 });
|
||||
@@ -310,7 +323,7 @@ options.port = process.env.PORT || 3000;
|
||||
// Bun's default cap is 128 MB, which would 4xx a /api/transcribe upload of
|
||||
// more than ~35 minutes of raw PCM before the route's own limit applies.
|
||||
options.maxRequestBodySize = MAX_UPLOAD_BYTES;
|
||||
options.websocket = liveWebSocket as any;
|
||||
options.websocket = liveWebSocket;
|
||||
|
||||
const server = serve(options);
|
||||
|
||||
|
||||
Reference in new issue
Block a user