This commit is contained in:
Sakurasan
2023-08-11 22:42:14 +08:00
parent a481a0eb7e
commit b3b4f6bba1

View File

@@ -443,7 +443,7 @@ func HandleProy(c *gin.Context) {
auth := c.Request.Header.Get("Authorization") auth := c.Request.Header.Get("Authorization")
if len(auth) > 7 && auth[:7] == "Bearer " { if len(auth) > 7 && auth[:7] == "Bearer " {
localuser = store.IsExistAuthCache(auth[7:]) localuser = store.IsExistAuthCache(auth[7:])
c.Set("localuser", localuser) c.Set("localuser", auth[7:])
} }
if c.Request.URL.Path == "/v1/audio/transcriptions" { if c.Request.URL.Path == "/v1/audio/transcriptions" {
WhisperProxy(c) WhisperProxy(c)
@@ -869,11 +869,17 @@ func WhisperProxy(c *gin.Context) {
}) })
return return
} }
if key.EndPoint == "" {
targetUrl, _ := url.ParseRequestURI(key.EndPoint) key.EndPoint = "https://api.openai.com"
}
targetUrl, _ := url.ParseRequestURI(key.EndPoint + c.Request.URL.String())
log.Println(targetUrl)
proxy := httputil.NewSingleHostReverseProxy(targetUrl) proxy := httputil.NewSingleHostReverseProxy(targetUrl)
proxy.Director = func(req *http.Request) { proxy.Director = func(req *http.Request) {
req.Header.Set("Content-Type", "application/json") req.Host = targetUrl.Host
req.URL.Scheme = targetUrl.Scheme
req.URL.Host = targetUrl.Host
req.Header.Set("Authorization", "Bearer "+key.Key) req.Header.Set("Authorization", "Bearer "+key.Key)
} }