MCPcopy
hub / github.com/erictik/midjourney-api / submit

Function submit

src/gradio/client.ts:350–651  ·  view source on GitHub ↗
(
        endpoint: string | number,
        data: unknown[],
        event_data?: unknown
      )

Source from the content-addressed store, hash-verified

348 }
349
350 function submit(
351 endpoint: string | number,
352 data: unknown[],
353 event_data?: unknown
354 ): SubmitReturn {
355 let fn_index: number;
356 let api_info: EndpointInfo<JsApiData>;
357
358 if (typeof endpoint === "number") {
359 fn_index = endpoint;
360 api_info = api.unnamed_endpoints[fn_index];
361 } else {
362 const trimmed_endpoint = endpoint.replace(/^\//, "");
363
364 fn_index = api_map[trimmed_endpoint];
365 api_info = api.named_endpoints[endpoint.trim()];
366 }
367
368 if (typeof fn_index !== "number") {
369 throw new Error(
370 "There is no endpoint matching that name of fn_index matching that number."
371 );
372 }
373
374 let websocket: WebSocket;
375
376 const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
377 let payload: Payload;
378 let complete: false | Record<string, any> = false;
379 const listener_map: ListenerMap<EventType> = {};
380
381 handle_blob(
382 `${http_protocol}//${host + config.path}`,
383 data,
384 api_info,
385 hf_token
386 ).then((_payload) => {
387 payload = { data: _payload || [], event_data, fn_index };
388 if (skip_queue(fn_index, config)) {
389 fire_event({
390 type: "status",
391 endpoint: _endpoint,
392 stage: "pending",
393 queue: false,
394 fn_index,
395 time: new Date(),
396 });
397
398 post_data(
399 `${http_protocol}//${host + config.path}/run${
400 _endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
401 }`,
402 {
403 ...payload,
404 session_hash,
405 },
406 hf_token
407 )

Callers 1

predictFunction · 0.85

Calls 7

handle_blobFunction · 0.85
skip_queueFunction · 0.85
fire_eventFunction · 0.85
post_dataFunction · 0.85
transform_outputFunction · 0.85
handle_messageFunction · 0.85
closeMethod · 0.80

Tested by

no test coverage detected