diff --git a/gen_web.go b/gen_web.go index 8ae0d4a..1f9e64e 100644 --- a/gen_web.go +++ b/gen_web.go @@ -87,7 +87,7 @@ import ( "github.com/gin-gonic/gin" ) -func RouteWebPages(route *gin.RouterGroup) { +func RouteWebPages(route gin.IRouter) { route.GET("/", func(c *gin.Context) { etag := fmt.Sprintf("%x", md5.Sum(Indexhtml)) c.Header("Cache-Control", "public, max-age=31536000") diff --git a/server/web/api/route.go b/server/web/api/route.go index 94002d4..7c1d263 100644 --- a/server/web/api/route.go +++ b/server/web/api/route.go @@ -1,6 +1,7 @@ package api import ( + config "server/settings" "server/web/auth" "github.com/gin-gonic/gin" @@ -39,7 +40,11 @@ func SetupRoute(route gin.IRouter) { authorized.GET("/download/:size", download) - authorized.GET("/search/*query", rutorSearch) - + if config.SearchWA { + route.GET("/search/*query", rutorSearch) + } else { + authorized.GET("/search/*query", rutorSearch) + } + authorized.GET("/ffp/:hash/:id", ffp) } diff --git a/server/web/auth/auth.go b/server/web/auth/auth.go index bcc60f5..b125f39 100644 --- a/server/web/auth/auth.go +++ b/server/web/auth/auth.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "path/filepath" + "slices" "unsafe" "github.com/gin-gonic/gin" @@ -68,12 +69,16 @@ func BasicAuth(accounts gin.Accounts) gin.HandlerFunc { } } -func CheckAuth() gin.HandlerFunc { +func CheckAuth(exclude ...string) gin.HandlerFunc { return func(c *gin.Context) { if !settings.HttpAuth { return } + if slices.Contains(exclude, c.FullPath()) { + return + } + if _, ok := c.Get(gin.AuthUserKey); ok { return } diff --git a/server/web/pages/route.go b/server/web/pages/route.go index 96a100f..4649ad8 100644 --- a/server/web/pages/route.go +++ b/server/web/pages/route.go @@ -11,7 +11,7 @@ import ( ) func SetupRoute(route gin.IRouter) { - authorized := route.Group("/", auth.CheckAuth()) + authorized := route.Group("/", auth.CheckAuth("/site.webmanifest")) template.RouteWebPages(authorized) authorized.GET("/stat", statPage)