MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / getAndValidImageRequest

Function getAndValidImageRequest

relay/image_handler.go:25–109  ·  view source on GitHub ↗
(c *gin.Context, info *relaycommon.RelayInfo)

Source from the content-addressed store, hash-verified

23)
24
25func getAndValidImageRequest(c *gin.Context, info *relaycommon.RelayInfo) (*dto.ImageRequest, error) {
26 imageRequest := &dto.ImageRequest{}
27
28 switch info.RelayMode {
29 case relayconstant.RelayModeImagesEdits:
30 _, err := c.MultipartForm()
31 if err != nil {
32 return nil, err
33 }
34 formData := c.Request.PostForm
35 imageRequest.Prompt = formData.Get("prompt")
36 imageRequest.Model = formData.Get("model")
37 imageRequest.N = common.String2Int(formData.Get("n"))
38 imageRequest.Quality = formData.Get("quality")
39 imageRequest.Size = formData.Get("size")
40
41 if imageRequest.Model == "gpt-image-1" {
42 if imageRequest.Quality == "" {
43 imageRequest.Quality = "standard"
44 }
45 }
46 if imageRequest.N == 0 {
47 imageRequest.N = 1
48 }
49
50 if info.ApiType == constant.APITypeVolcEngine {
51 watermark := formData.Has("watermark")
52 imageRequest.Watermark = &watermark
53 }
54 default:
55 err := common.UnmarshalBodyReusable(c, imageRequest)
56 if err != nil {
57 return nil, err
58 }
59
60 if imageRequest.Model == "" {
61 imageRequest.Model = "dall-e-3"
62 }
63
64 if strings.Contains(imageRequest.Size, "×") {
65 return nil, errors.New("size an unexpected error occurred in the parameter, please use 'x' instead of the multiplication sign '×'")
66 }
67
68 // Not "256x256", "512x512", or "1024x1024"
69 if imageRequest.Model == "dall-e-2" || imageRequest.Model == "dall-e" {
70 if imageRequest.Size != "" && imageRequest.Size != "256x256" && imageRequest.Size != "512x512" && imageRequest.Size != "1024x1024" {
71 return nil, errors.New("size must be one of 256x256, 512x512, or 1024x1024 for dall-e-2 or dall-e")
72 }
73 if imageRequest.Size == "" {
74 imageRequest.Size = "1024x1024"
75 }
76 } else if imageRequest.Model == "dall-e-3" {
77 if imageRequest.Size != "" && imageRequest.Size != "1024x1024" && imageRequest.Size != "1024x1792" && imageRequest.Size != "1792x1024" {
78 return nil, errors.New("size must be one of 1024x1024, 1024x1792 or 1792x1024 for dall-e-3")
79 }
80 if imageRequest.Quality == "" {
81 imageRequest.Quality = "standard"
82 }

Callers 1

ImageHelperFunction · 0.85

Calls 4

CheckSensitiveInputFunction · 0.92
GetMethod · 0.80
ContainsMethod · 0.80

Tested by

no test coverage detected