- Replace all encoding/json direct calls with common.Marshal/Unmarshal/DecodeJson per Rule 1 - Fix Dify nil pointer dereference on remote image upload (relay-dify.go) - Fix Claude relay file content type detection for text/* and PDF (relay-claude.go) - Fix unsafe type assertions in Claude relay and Vertex GetModelRegion - Fix StreamScanner unconditionally resetting pre-existing StreamStatus - Add inferMimeTypeFromFilename() for proper MIME type handling in DTO - Fix Mac build script hardcoded DMG version (now reads from tauri.conf.json) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"github.com/heicode/manager/common"
|
|
"github.com/heicode/manager/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func KlingRequestConvert() func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
var originalReq map[string]interface{}
|
|
if err := common.UnmarshalBodyReusable(c, &originalReq); err != nil {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
// Support both model_name and model fields
|
|
model, _ := originalReq["model_name"].(string)
|
|
if model == "" {
|
|
model, _ = originalReq["model"].(string)
|
|
}
|
|
prompt, _ := originalReq["prompt"].(string)
|
|
|
|
unifiedReq := map[string]interface{}{
|
|
"model": model,
|
|
"prompt": prompt,
|
|
"metadata": originalReq,
|
|
}
|
|
|
|
jsonData, err := common.Marshal(unifiedReq)
|
|
if err != nil {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
// Rewrite request body and path
|
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(jsonData))
|
|
c.Request.URL.Path = "/v1/video/generations"
|
|
if image, ok := originalReq["image"]; !ok || image == "" {
|
|
c.Set("action", constant.TaskActionTextGenerate)
|
|
}
|
|
|
|
// We have to reset the request body for the next handlers
|
|
c.Set(common.KeyRequestBody, jsonData)
|
|
c.Next()
|
|
}
|
|
}
|