Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions common/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"bytes"
"encoding/json"
"io"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -41,11 +40,11 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error {
//}
contentType := c.Request.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "application/json") {
err = Unmarshal(requestBody, &v)
err = Unmarshal(requestBody, v)
} else if strings.Contains(contentType, gin.MIMEPOSTForm) {
err = parseFormData(requestBody, &v)
err = parseFormData(requestBody, v)
} else if strings.Contains(contentType, gin.MIMEMultipartPOSTForm) {
err = parseMultipartFormData(c, requestBody, &v)
err = parseMultipartFormData(c, requestBody, v)
} else {
// skip for now
// TODO: someday non json request have variant model, we will need to implementation this
Expand Down Expand Up @@ -145,6 +144,20 @@ func ParseMultipartFormReusable(c *gin.Context) (*multipart.Form, error) {
return form, nil
}

func processFormMap(formMap map[string]any, v any) error {
jsonData, err := Marshal(formMap)
if err != nil {
return err
}

err = Unmarshal(jsonData, v)
if err != nil {
return err
}

return nil
}

func parseFormData(data []byte, v any) error {
values, err := url.ParseQuery(string(data))
if err != nil {
Expand All @@ -158,12 +171,8 @@ func parseFormData(data []byte, v any) error {
formMap[key] = vals
}
}
jsonData, err := json.Marshal(formMap)
if err != nil {
return err
}

return Unmarshal(jsonData, v)
return processFormMap(formMap, v)
}

func parseMultipartFormData(c *gin.Context, data []byte, v any) error {
Expand Down Expand Up @@ -191,10 +200,6 @@ func parseMultipartFormData(c *gin.Context, data []byte, v any) error {
formMap[key] = vals
}
}
jsonData, err := Marshal(formMap)
if err != nil {
return err
}

return Unmarshal(jsonData, v)
return processFormMap(formMap, v)
}
8 changes: 6 additions & 2 deletions controller/video_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ func VideoProxy(c *gin.Context) {
return
}

if channel.Type == constant.ChannelTypeGemini {
switch channel.Type {
case constant.ChannelTypeGemini:
videoURL = fmt.Sprintf("%s&key=%s", c.Query("url"), channel.Key)
req.Header.Set("x-goog-api-key", channel.Key)
} else {
case constant.ChannelTypeAli:
// Video URL is directly in task.FailReason
videoURL = task.FailReason
default:
// Default (Sora, etc.): Use original logic
videoURL = fmt.Sprintf("%s/v1/videos/%s/content", baseURL, task.TaskID)
req.Header.Set("Authorization", "Bearer "+channel.Key)
Expand Down
Loading