chore: common err resp log

This commit is contained in:
Noah Hsu
2022-06-28 18:12:53 +08:00
parent 67bc66fedf
commit d1efec4539
10 changed files with 68 additions and 56 deletions

View File

@ -4,7 +4,7 @@ import (
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/setting"
common2 "github.com/alist-org/alist/v3/server/common"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
)
@ -15,7 +15,7 @@ func Auth(c *gin.Context) {
if token == setting.GetByKey("token") {
admin, err := db.GetAdmin()
if err != nil {
common2.ErrorResp(c, err, 500)
common.ErrorResp(c, err, 500)
c.Abort()
return
}
@ -26,7 +26,7 @@ func Auth(c *gin.Context) {
if token == "" {
guest, err := db.GetGuest()
if err != nil {
common2.ErrorResp(c, err, 500)
common.ErrorResp(c, err, 500)
c.Abort()
return
}
@ -34,15 +34,15 @@ func Auth(c *gin.Context) {
c.Next()
return
}
userClaims, err := common2.ParseToken(token)
userClaims, err := common.ParseToken(token)
if err != nil {
common2.ErrorResp(c, err, 401, true)
common.ErrorResp(c, err, 401)
c.Abort()
return
}
user, err := db.GetUserByName(userClaims.Username)
if err != nil {
common2.ErrorResp(c, err, 401)
common.ErrorResp(c, err, 401)
c.Abort()
return
}
@ -53,7 +53,7 @@ func Auth(c *gin.Context) {
func AuthAdmin(c *gin.Context) {
user := c.MustGet("user").(*model.User)
if !user.IsAdmin() {
common2.ErrorStrResp(c, "You are not an admin", 403, true)
common.ErrorStrResp(c, "You are not an admin", 403)
c.Abort()
} else {
c.Next()