()
| 11 | ) |
| 12 | |
| 13 | func 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 | } |
no test coverage detected