From 6ded638f70962ace1b34beda2262d1fbb0517269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E5=8D=97=E4=B8=80=E6=A0=B9=E8=91=B1?= Date: Sun, 2 Feb 2025 22:22:42 +0800 Subject: [PATCH] fix: audio transcription 400 error (#1882) (#2003) --- common/gin.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/gin.go b/common/gin.go index 815b4ee5..e3281fee 100644 --- a/common/gin.go +++ b/common/gin.go @@ -3,10 +3,11 @@ package common import ( "bytes" "encoding/json" - "github.com/gin-gonic/gin" - "github.com/songquanpeng/one-api/common/ctxkey" "io" "strings" + + "github.com/gin-gonic/gin" + "github.com/songquanpeng/one-api/common/ctxkey" ) func GetRequestBody(c *gin.Context) ([]byte, error) { @@ -31,7 +32,6 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error { contentType := c.Request.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/json") { err = json.Unmarshal(requestBody, &v) - c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody)) } else { c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody)) err = c.ShouldBind(&v) @@ -40,6 +40,7 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error { return err } // Reset request body + c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody)) return nil }