From b2f5d733486023e4ba1489349e2b0c8b0a489d37 Mon Sep 17 00:00:00 2001 From: Sakurasan <1173092237@qq.com> Date: Fri, 31 Mar 2023 18:21:57 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opencat.go | 4 ++-- router/router.go | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/opencat.go b/opencat.go index f5dfdb1..f742f5f 100644 --- a/opencat.go +++ b/opencat.go @@ -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") } diff --git a/router/router.go b/router/router.go index de5d75d..3f793bd 100644 --- a/router/router.go +++ b/router/router.go @@ -231,15 +231,14 @@ 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 } - localuser = true } client := http.DefaultClient tr := &http.Transport{