fix 自定义域名验证逻辑

This commit is contained in:
Sakurasan
2023-03-31 18:21:57 +08:00
parent 8c75f9575b
commit b2f5d73348
2 changed files with 5 additions and 6 deletions

View File

@@ -41,8 +41,8 @@ func main() {
// 初始化用户
r.POST("/1/users/init", router.Handleinit)
r.Any("/v1/chat/completions", router.HandleProy)
r.Any("/", router.HandleProy)
r.POST("/v1/chat/completions", router.HandleProy)
r.GET("/v1/models", router.HandleProy)
r.Run(":80")
}

View File

@@ -231,16 +231,15 @@ func GenerateToken() string {
func HandleProy(c *gin.Context) {
var localuser bool
auth := c.Request.Header.Get("Authorization")
if auth[:7] == "Bearer " {
if len(auth) > 7 && auth[:7] == "Bearer " {
if len(auth[7:]) < 1 {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
if !store.IsExistAuthCache(auth[7:]) {
localuser = false
}
if store.IsExistAuthCache(auth[7:]) {
localuser = true
}
}
client := http.DefaultClient
tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,