Repository navigation
修复豆包图像编辑(图生图)功能 #2090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复豆包图像编辑(图生图)功能 #2090
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |||||||||||||||||
| "errors" | ||||||||||||||||||
| "fmt" | ||||||||||||||||||
| "net/http" | ||||||||||||||||||
| "slices" | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Unused import after fixing the Content-Type check. After applying the fix above, the 🤖 Prompt for AI Agents |
||||||||||||||||||
| "strconv" | ||||||||||||||||||
| "strings" | ||||||||||||||||||
| "time" | ||||||||||||||||||
|
|
@@ -245,7 +246,8 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) { | |||||||||||||||||
| modelRequest.Model = common.GetStringIfEmpty(modelRequest.Model, "dall-e") | ||||||||||||||||||
| } else if strings.HasPrefix(c.Request.URL.Path, "/v1/images/edits") { | ||||||||||||||||||
| //modelRequest.Model = common.GetStringIfEmpty(c.PostForm("model"), "gpt-image-1") | ||||||||||||||||||
| if strings.Contains(c.Request.Header.Get("Content-Type"), "multipart/form-data") { | ||||||||||||||||||
| contentType := c.Request.Header.Get("Content-Type") | ||||||||||||||||||
| if slices.Contains([]string{gin.MIMEPOSTForm, gin.MIMEMultipartPOSTForm}, contentType) { | ||||||||||||||||||
| modelRequest.Model = c.PostForm("model") | ||||||||||||||||||
| } | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Content-Type matching will fail for real requests. The exact match check using Note that Apply this diff to fix the Content-Type matching: - contentType := c.Request.Header.Get("Content-Type")
- if slices.Contains([]string{gin.MIMEPOSTForm, gin.MIMEMultipartPOSTForm}, contentType) {
+ contentType := c.Request.Header.Get("Content-Type")
+ if strings.Contains(contentType, gin.MIMEPOSTForm) || strings.Contains(contentType, gin.MIMEMultipartPOSTForm) {
modelRequest.Model = c.PostForm("model")
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questionable fallback: Missing boundary should be an error.
If
Content-Typeismultipart/form-databut theboundaryparameter is missing, that's a malformed request. Falling back to JSON parsing (line 177) masks this error and could lead to confusing behavior.Consider returning an error instead:
if boundary == "" { - return json.Unmarshal(data, v) // Fallback to JSON + return errors.New("multipart/form-data Content-Type is missing required boundary parameter") }📝 Committable suggestion
🤖 Prompt for AI Agents