(c *gin.Context)
| 97 | } |
| 98 | |
| 99 | func doGeneration(c *gin.Context) { |
| 100 | var genRequest GenRequest |
| 101 | err := c.BindJSON(&genRequest) |
| 102 | if err != nil { |
| 103 | WrapperLumaError(c, err, http.StatusBadRequest) |
| 104 | return |
| 105 | } |
| 106 | if genRequest.ImageUrl != "" && !strings.HasPrefix(genRequest.ImageUrl, "https://storage.cdn-luma.com/app_data/photon") { |
| 107 | uploadRes, relayErr := uploadFile(genRequest.ImageUrl) |
| 108 | if relayErr != nil { |
| 109 | ReturnLumaError(c, relayErr.ErrorResp, relayErr.StatusCode) |
| 110 | return |
| 111 | } |
| 112 | common.Logger.Infow("upload file success", "uploadRes", uploadRes) |
| 113 | genRequest.ImageUrl = uploadRes.PublicUrl |
| 114 | } |
| 115 | |
| 116 | if genRequest.ImageEndUrl != "" && !strings.HasPrefix(genRequest.ImageEndUrl, "https://storage.cdn-luma.com/app_data/photon") { |
| 117 | uploadRes, relayErr := uploadFile(genRequest.ImageEndUrl) |
| 118 | if relayErr != nil { |
| 119 | ReturnLumaError(c, relayErr.ErrorResp, relayErr.StatusCode) |
| 120 | return |
| 121 | } |
| 122 | common.Logger.Infow("upload file success", "uploadRes", uploadRes) |
| 123 | genRequest.ImageEndUrl = uploadRes.PublicUrl |
| 124 | } |
| 125 | |
| 126 | reqData, _ := json.Marshal(genRequest) |
| 127 | url := common.BaseUrl + SubmitEndpoint |
| 128 | if strings.HasSuffix(c.Request.URL.Path, "/extend") { |
| 129 | paths := strings.Split(c.Request.URL.Path, "/generations/") |
| 130 | url += paths[1] |
| 131 | } |
| 132 | resp, err := DoRequest("POST", url, bytes.NewReader(reqData), nil) |
| 133 | if err != nil { |
| 134 | WrapperLumaError(c, err, http.StatusInternalServerError) |
| 135 | return |
| 136 | } |
| 137 | defer resp.Body.Close() |
| 138 | |
| 139 | if resp.StatusCode >= 400 { |
| 140 | c.Writer.WriteHeader(resp.StatusCode) |
| 141 | for key, values := range resp.Header { |
| 142 | for _, value := range values { |
| 143 | c.Writer.Header().Add(key, value) |
| 144 | } |
| 145 | } |
| 146 | // 读取响应体 |
| 147 | _, err = io.Copy(c.Writer, resp.Body) |
| 148 | if err != nil { |
| 149 | WrapperLumaError(c, err, http.StatusInternalServerError) |
| 150 | return |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | body, err := io.ReadAll(resp.Body) |
| 155 | if err != nil { |
| 156 | WrapperLumaError(c, err, http.StatusInternalServerError) |
no test coverage detected