( req: http.IncomingMessage, res: http.ServerResponse, raw: string, fixtures: Fixture[], journal: Journal, defaults: HandlerDefaults, setCorsHeaders: (res: http.ServerResponse) => void, jobs: OpenRouterVideoJobMap, )
| 1304 | // ─── POST /api/v1/videos — submit ─────────────────────────────────────────── |
| 1305 | |
| 1306 | export async function handleOpenRouterVideoCreate( |
| 1307 | req: http.IncomingMessage, |
| 1308 | res: http.ServerResponse, |
| 1309 | raw: string, |
| 1310 | fixtures: Fixture[], |
| 1311 | journal: Journal, |
| 1312 | defaults: HandlerDefaults, |
| 1313 | setCorsHeaders: (res: http.ServerResponse) => void, |
| 1314 | jobs: OpenRouterVideoJobMap, |
| 1315 | ): Promise<void> { |
| 1316 | setCorsHeaders(res); |
| 1317 | const path = req.url ?? "/api/v1/videos"; |
| 1318 | const method = req.method ?? "POST"; |
| 1319 | |
| 1320 | let videoReq: OpenRouterVideoRequest; |
| 1321 | try { |
| 1322 | videoReq = JSON.parse(raw) as OpenRouterVideoRequest; |
| 1323 | } catch (parseErr) { |
| 1324 | const detail = parseErr instanceof Error ? parseErr.message : "unknown"; |
| 1325 | journal.add({ |
| 1326 | method, |
| 1327 | path, |
| 1328 | headers: flattenHeaders(req.headers), |
| 1329 | body: null, |
| 1330 | response: { status: 400, fixture: null }, |
| 1331 | }); |
| 1332 | writeErrorResponse( |
| 1333 | res, |
| 1334 | 400, |
| 1335 | JSON.stringify({ |
| 1336 | error: { |
| 1337 | message: `Malformed JSON: ${detail}`, |
| 1338 | type: "invalid_request_error", |
| 1339 | code: "invalid_json", |
| 1340 | }, |
| 1341 | }), |
| 1342 | ); |
| 1343 | return; |
| 1344 | } |
| 1345 | |
| 1346 | // Reject bodies that parsed but are not a JSON object (null, arrays, |
| 1347 | // numbers, strings) before touching any fields — mirrors fal's parseBody |
| 1348 | // guard so callers get a 400 instead of a raw TypeError 500. |
| 1349 | if (videoReq === null || typeof videoReq !== "object" || Array.isArray(videoReq)) { |
| 1350 | journal.add({ |
| 1351 | method, |
| 1352 | path, |
| 1353 | headers: flattenHeaders(req.headers), |
| 1354 | body: null, |
| 1355 | response: { status: 400, fixture: null }, |
| 1356 | }); |
| 1357 | writeErrorResponse( |
| 1358 | res, |
| 1359 | 400, |
| 1360 | JSON.stringify({ |
| 1361 | error: { |
| 1362 | message: "Request body must be a JSON object", |
| 1363 | type: "invalid_request_error", |
no test coverage detected
searching dependent graphs…