mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
refactor HTTP error.
This commit is contained in:
@ -25,7 +25,7 @@ func AdminsOnly(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := GetSession(r)
|
||||
if !session.Profile().IsAdmin {
|
||||
utils.HttpForbidden(w)
|
||||
utils.HttpForbidden(w).Msg("session is not admin")
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
@ -36,7 +36,7 @@ func HostsOnly(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := GetSession(r)
|
||||
if !session.IsHost() {
|
||||
utils.HttpForbidden(w, "only host can do this")
|
||||
utils.HttpForbidden(w).Msg("session is not host")
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
@ -47,7 +47,7 @@ func CanWatchOnly(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := GetSession(r)
|
||||
if !session.Profile().CanWatch {
|
||||
utils.HttpForbidden(w)
|
||||
utils.HttpForbidden(w).Msg("session cannot watch")
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
@ -58,7 +58,7 @@ func CanHostOnly(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := GetSession(r)
|
||||
if !session.Profile().CanHost {
|
||||
utils.HttpForbidden(w)
|
||||
utils.HttpForbidden(w).Msg("session cannot host")
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
@ -69,7 +69,7 @@ func CanAccessClipboardOnly(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := GetSession(r)
|
||||
if !session.Profile().CanAccessClipboard {
|
||||
utils.HttpForbidden(w)
|
||||
utils.HttpForbidden(w).Msg("session cannot access clipboard")
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
"demodesk/neko/internal/config"
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
type HttpManagerCtx struct {
|
||||
@ -55,13 +54,13 @@ func New(WebSocketManager types.WebSocketManager, ApiManager types.ApiManager, c
|
||||
if _, err := os.Stat(config.Static + r.URL.Path); !os.IsNotExist(err) {
|
||||
fs.ServeHTTP(w, r)
|
||||
} else {
|
||||
utils.HttpNotFound(w)
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
router.NotFound(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
utils.HttpNotFound(w)
|
||||
http.NotFound(w, r)
|
||||
}))
|
||||
|
||||
return &HttpManagerCtx{
|
||||
|
Reference in New Issue
Block a user