feat: support openai images edits api

This commit is contained in:
Laisky.Cai
2024-04-25 03:02:20 +00:00
parent da0842272c
commit f71e4ef151
17 changed files with 87 additions and 52 deletions

View File

@@ -2,10 +2,10 @@ package common
import (
"bytes"
"encoding/json"
"github.com/gin-gonic/gin"
"io"
"strings"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
const KeyRequestBody = "key_request_body"
@@ -29,18 +29,16 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error {
if err != nil {
return err
}
contentType := c.Request.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "application/json") {
err = json.Unmarshal(requestBody, &v)
} else {
// skip for now
// TODO: someday non json request have variant model, we will need to implementation this
}
if err != nil {
return err
}
// Reset request body
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
defer func() {
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
}()
if err = c.Bind(v); err != nil {
return errors.Wrap(err, "bind request body failed")
}
return nil
}