diff --git a/proxy/proxy.go b/proxy/proxy.go index d6f357a..c37b2f9 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -8,7 +8,6 @@ import ( "strconv" "strings" - "ghproxy/auth" "ghproxy/config" "ghproxy/logger" @@ -47,7 +46,7 @@ func NoRouteHandler(config *config.Config) gin.HandlerFunc { rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1) } - if !auth.AuthHandler(c) { + if !AuthHandler(c) { c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"}) logw("Unauthorized request: %s", rawPath) return @@ -190,3 +189,23 @@ func checkURL(u string) []string { logw("Invalid URL: %s", u) return nil } + +func AuthHandler(c *gin.Context) bool { + // 如果身份验证未启用,直接返回 true + if !cfg.Auth { + logw("auth PASS") + return true + } + + // 获取 auth_token 参数 + authToken := c.Query("auth_token") + logw("auth_token: ", authToken) + + // 验证 token + isValid := authToken == cfg.AuthToken + if !isValid { + logw("auth FAIL") + } + + return isValid +}