isolate web pages auth logic

This commit is contained in:
Viacheslav Evseev
2024-02-22 05:53:55 +03:00
parent 3695797f74
commit b50e5a381e
2 changed files with 14 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
package pages
import (
"slices"
"github.com/anacrolix/torrent/metainfo"
"github.com/gin-gonic/gin"
@@ -11,9 +13,18 @@ import (
)
func SetupRoute(route gin.IRouter) {
authorized := route.Group("/", auth.CheckAuth("/site.webmanifest"))
authorized := route.Group("/", auth.CheckAuth())
template.RouteWebPages(authorized)
webPagesAuth := route.Group("/", func() gin.HandlerFunc {
return func(c *gin.Context) {
if slices.Contains([]string{"/site.webmanifest"}, c.FullPath()) {
return
}
auth.CheckAuth()(c)
}
}())
template.RouteWebPages(webPagesAuth)
authorized.GET("/stat", statPage)
authorized.GET("/magnets", getTorrents)
}