mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
24w06b
This commit is contained in:
parent
7d6d9d0da5
commit
bb4e2d8ae7
1 changed files with 9 additions and 2 deletions
11
main.go
11
main.go
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"ghproxy/auth"
|
|
||||||
"ghproxy/config"
|
"ghproxy/config"
|
||||||
"ghproxy/logger"
|
"ghproxy/logger"
|
||||||
|
|
||||||
|
|
@ -97,6 +96,14 @@ func api(c *gin.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AuthHandler(c *gin.Context) bool {
|
||||||
|
if cfg.Auth {
|
||||||
|
authToken := c.Query("auth_token")
|
||||||
|
return authToken == cfg.AuthToken
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func noRouteHandler(config *config.Config) gin.HandlerFunc {
|
func noRouteHandler(config *config.Config) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/")
|
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/")
|
||||||
|
|
@ -115,7 +122,7 @@ func noRouteHandler(config *config.Config) gin.HandlerFunc {
|
||||||
rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !auth.AuthHandler(c) {
|
if !AuthHandler(c) {
|
||||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||||
logw("Unauthorized request: %s", rawPath)
|
logw("Unauthorized request: %s", rawPath)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue