MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / KlingRequestConvert

Function KlingRequestConvert

middleware/kling_adapter.go:13–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func KlingRequestConvert() func(c *gin.Context) {
14 return func(c *gin.Context) {
15 var originalReq map[string]interface{}
16 if err := common.UnmarshalBodyReusable(c, &originalReq); err != nil {
17 c.Next()
18 return
19 }
20
21 model, _ := originalReq["model_name"].(string)
22 prompt, _ := originalReq["prompt"].(string)
23
24 unifiedReq := map[string]interface{}{
25 "model": model,
26 "prompt": prompt,
27 "metadata": originalReq,
28 }
29
30 jsonData, err := json.Marshal(unifiedReq)
31 if err != nil {
32 c.Next()
33 return
34 }
35
36 // Rewrite request body and path
37 c.Request.Body = io.NopCloser(bytes.NewBuffer(jsonData))
38 c.Request.URL.Path = "/v1/video/generations"
39 if image, ok := originalReq["image"]; !ok || image == "" {
40 c.Set("action", constant.TaskActionTextGenerate)
41 }
42
43 // We have to reset the request body for the next handlers
44 c.Set(common.KeyRequestBody, jsonData)
45 c.Next()
46 }
47}

Callers 1

SetVideoRouterFunction · 0.92

Calls 2

UnmarshalBodyReusableFunction · 0.92
NextMethod · 0.80

Tested by

no test coverage detected