MCPcopy Create free account
hub / github.com/CopilotKit/aimock / handleOpenRouterVideoCreate

Function handleOpenRouterVideoCreate

src/openrouter-video.ts:1306–1668  ·  view source on GitHub ↗
(
  req: http.IncomingMessage,
  res: http.ServerResponse,
  raw: string,
  fixtures: Fixture[],
  journal: Journal,
  defaults: HandlerDefaults,
  setCorsHeaders: (res: http.ServerResponse) => void,
  jobs: OpenRouterVideoJobMap,
)

Source from the content-addressed store, hash-verified

1304// ─── POST /api/v1/videos — submit ───────────────────────────────────────────
1305
1306export 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",

Callers 1

handleHttpRequestFunction · 0.85

Calls 15

setCorsHeadersFunction · 0.85
flattenHeadersFunction · 0.85
writeErrorResponseFunction · 0.85
getContextFunction · 0.85
getTestIdFunction · 0.85
matchFixtureDiagnosticFunction · 0.85
applyChaosFunction · 0.85
resolveStrictModeFunction · 0.85
strictNoMatchMessageFunction · 0.85
strictNoMatchLogLineFunction · 0.85
strictOverrideFieldFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…