up
This commit is contained in:
@@ -41,9 +41,10 @@ func main() {
|
|||||||
|
|
||||||
// 初始化用户
|
// 初始化用户
|
||||||
r.POST("/1/users/init", router.Handleinit)
|
r.POST("/1/users/init", router.Handleinit)
|
||||||
r.POST("/v1/chat/completions", router.HandleReverseProxy)
|
|
||||||
r.GET("/v1/models", router.HandleReverseProxy)
|
r.POST("/v1/chat/completions", router.HandleProy)
|
||||||
r.GET("/v1/dashboard/billing/credit_grants", router.HandleReverseProxy)
|
r.GET("/v1/models", router.HandleProy)
|
||||||
|
r.GET("/v1/dashboard/billing/credit_grants", router.HandleProy)
|
||||||
|
|
||||||
r.Run(":80")
|
r.Run(":80")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,9 +234,7 @@ func HandleProy(c *gin.Context) {
|
|||||||
var localuser bool
|
var localuser bool
|
||||||
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 " {
|
||||||
if store.IsExistAuthCache(auth[7:]) {
|
localuser = store.IsExistAuthCache(auth[7:])
|
||||||
localuser = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
client := http.DefaultClient
|
client := http.DefaultClient
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
@@ -346,20 +344,21 @@ func HandleReverseProxy(c *gin.Context) {
|
|||||||
localuser = store.IsExistAuthCache(auth[7:])
|
localuser = store.IsExistAuthCache(auth[7:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// req, err := http.NewRequest(c.Request.Method, baseUrl+c.Request.URL.Path, c.Request.Body)
|
req, err := http.NewRequest(c.Request.Method, c.Request.URL.Path, c.Request.Body)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// c.JSON(http.StatusOK, gin.H{"error": err.Error()})
|
c.JSON(http.StatusOK, gin.H{"error": err.Error()})
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
// req.Header = c.Request.Header
|
req.Header = c.Request.Header
|
||||||
if localuser {
|
if localuser {
|
||||||
if store.KeysCache.ItemCount() == 0 {
|
if store.KeysCache.ItemCount() == 0 {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "No Api-Key Available"})
|
c.JSON(http.StatusOK, gin.H{"error": "No Api-Key Available"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", store.FromKeyCacheRandomItem()))
|
// c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", store.FromKeyCacheRandomItem()))
|
||||||
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", store.FromKeyCacheRandomItem()))
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy.ServeHTTP(c.Writer, c.Request)
|
proxy.ServeHTTP(c.Writer, req)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user