优化路由权限校验
This commit is contained in:
parent
c891f7e016
commit
67155ff5c0
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -27,17 +28,30 @@ func ErrorHandler(next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
|
|
||||||
func Auth(next echo.HandlerFunc) echo.HandlerFunc {
|
func Auth(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
|
|
||||||
urls := []string{"/download", "/recording", "/login", "/static", "/favicon.ico", "/logo.svg", "/asciinema"}
|
startWithUrls := []string{"/login", "/static", "/favicon.ico", "/logo.svg", "/asciinema"}
|
||||||
|
|
||||||
|
download := regexp.MustCompile(`/sessions/\w{8}(-\w{4}){3}-\w{12}/download`)
|
||||||
|
recording := regexp.MustCompile(`/sessions/\w{8}(-\w{4}){3}-\w{12}/recording`)
|
||||||
|
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
|
|
||||||
|
uri := c.Request().RequestURI
|
||||||
|
if uri == "/" || strings.HasPrefix(uri, "/#") {
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
// 路由拦截 - 登录身份、资源权限判断等
|
// 路由拦截 - 登录身份、资源权限判断等
|
||||||
for i := range urls {
|
for i := range startWithUrls {
|
||||||
if c.Request().RequestURI == "/" || strings.HasPrefix(c.Request().RequestURI, "/#") {
|
if strings.HasPrefix(uri, startWithUrls[i]) {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(c.Request().RequestURI, urls[i]) {
|
}
|
||||||
|
|
||||||
|
if download.FindString(uri) != "" {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if recording.FindString(uri) != "" {
|
||||||
|
return next(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
token := GetToken(c)
|
token := GetToken(c)
|
||||||
|
Loading…
Reference in New Issue
Block a user