mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
isolate web pages auth logic
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -69,16 +68,12 @@ func BasicAuth(accounts gin.Accounts) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAuth(exclude ...string) gin.HandlerFunc {
|
func CheckAuth() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
if !settings.HttpAuth {
|
if !settings.HttpAuth {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(exclude, c.FullPath()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := c.Get(gin.AuthUserKey); ok {
|
if _, ok := c.Get(gin.AuthUserKey); ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent/metainfo"
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
@@ -11,9 +13,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func SetupRoute(route gin.IRouter) {
|
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("/stat", statPage)
|
||||||
authorized.GET("/magnets", getTorrents)
|
authorized.GET("/magnets", getTorrents)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user