chore: common err resp log
This commit is contained in:
@ -1,19 +1,20 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/operations"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ListAccounts(c *gin.Context) {
|
||||
var req common.PageReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
log.Debugf("%+v", req)
|
||||
@ -31,11 +32,11 @@ func ListAccounts(c *gin.Context) {
|
||||
func CreateAccount(c *gin.Context) {
|
||||
var req model.Account
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := operations.CreateAccount(c, req); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
@ -44,11 +45,11 @@ func CreateAccount(c *gin.Context) {
|
||||
func UpdateAccount(c *gin.Context) {
|
||||
var req model.Account
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := operations.UpdateAccount(c, req); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
@ -58,11 +59,11 @@ func DeleteAccount(c *gin.Context) {
|
||||
idStr := c.Query("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := operations.DeleteAccountById(c, uint(id)); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c)
|
||||
|
@ -1,6 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
stdpath "path"
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
@ -12,8 +15,6 @@ import (
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
stdpath "path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Down(c *gin.Context) {
|
||||
@ -31,13 +32,13 @@ func Down(c *gin.Context) {
|
||||
s := c.Param("sign")
|
||||
err = sign.Verify(filename, s)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 401, true)
|
||||
common.ErrorResp(c, err, 401)
|
||||
return
|
||||
}
|
||||
}
|
||||
account, err := fs.GetAccount(rawPath)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
if needProxy(account, filename) {
|
||||
@ -45,12 +46,12 @@ func Down(c *gin.Context) {
|
||||
Header: c.Request.Header,
|
||||
})
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
obj, err := fs.Get(c, rawPath)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
err = common.Proxy(c.Writer, c.Request, link, obj)
|
||||
@ -64,7 +65,7 @@ func Down(c *gin.Context) {
|
||||
Header: c.Request.Header,
|
||||
})
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
c.Redirect(302, link.URL)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
stdpath "path"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
"github.com/alist-org/alist/v3/internal/fs"
|
||||
@ -8,7 +10,6 @@ import (
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
stdpath "path"
|
||||
)
|
||||
|
||||
type FsGetReq struct {
|
||||
@ -32,7 +33,7 @@ func FsGet(c *gin.Context) {
|
||||
meta, err := db.GetNearestMeta(req.Path)
|
||||
if err != nil {
|
||||
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -43,7 +44,7 @@ func FsGet(c *gin.Context) {
|
||||
}
|
||||
obj, err := fs.Get(c, req.Path)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, FsGetResp{
|
||||
|
@ -1,6 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
stdpath "path"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
"github.com/alist-org/alist/v3/internal/fs"
|
||||
@ -11,8 +14,6 @@ import (
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
stdpath "path"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ListReq struct {
|
||||
@ -57,7 +58,7 @@ func FsList(c *gin.Context) {
|
||||
}
|
||||
objs, err := fs.List(c, req.Path)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
total, objs := pagination(objs, &req.PageReq)
|
||||
|
@ -1,12 +1,13 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Xhofe/go-cache"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
|
||||
var loginCache = cache.NewMemCache[int]()
|
||||
@ -32,24 +33,24 @@ func Login(c *gin.Context) {
|
||||
// check username
|
||||
var req LoginReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
user, err := db.GetUserByName(req.Username)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
// validate password
|
||||
if err := user.ValidatePassword(req.Password); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
loginCache.Set(ip, count+1)
|
||||
return
|
||||
}
|
||||
// generate token
|
||||
token, err := common.GenerateToken(user.Username)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, gin.H{"token": token})
|
||||
|
@ -1,25 +1,26 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ListMetas(c *gin.Context) {
|
||||
var req common.PageReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
log.Debugf("%+v", req)
|
||||
metas, total, err := db.GetMetas(req.PageIndex, req.PageSize)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, common.PageResp{
|
||||
@ -31,12 +32,12 @@ func ListMetas(c *gin.Context) {
|
||||
func CreateMeta(c *gin.Context) {
|
||||
var req model.Meta
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
req.Path = utils.StandardizePath(req.Path)
|
||||
if err := db.CreateMeta(&req); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
@ -45,12 +46,12 @@ func CreateMeta(c *gin.Context) {
|
||||
func UpdateMeta(c *gin.Context) {
|
||||
var req model.Meta
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
req.Path = utils.StandardizePath(req.Path)
|
||||
if err := db.UpdateMeta(&req); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
@ -60,11 +61,11 @@ func DeleteMeta(c *gin.Context) {
|
||||
idStr := c.Query("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := db.DeleteMetaById(uint(id)); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c)
|
||||
|
@ -1,24 +1,25 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ListUsers(c *gin.Context) {
|
||||
var req common.PageReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
log.Debugf("%+v", req)
|
||||
users, total, err := db.GetUsers(req.PageIndex, req.PageSize)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, common.PageResp{
|
||||
@ -30,7 +31,7 @@ func ListUsers(c *gin.Context) {
|
||||
func CreateUser(c *gin.Context) {
|
||||
var req model.User
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if req.IsAdmin() || req.IsGuest() {
|
||||
@ -38,7 +39,7 @@ func CreateUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := db.CreateUser(&req); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
@ -47,16 +48,16 @@ func CreateUser(c *gin.Context) {
|
||||
func UpdateUser(c *gin.Context) {
|
||||
var req model.User
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
user, err := db.GetUserById(req.ID)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
if user.Role != req.Role {
|
||||
common.ErrorStrResp(c, "role can not be changed", 400, true)
|
||||
common.ErrorStrResp(c, "role can not be changed", 400)
|
||||
return
|
||||
}
|
||||
if err := db.UpdateUser(&req); err != nil {
|
||||
@ -70,7 +71,7 @@ func DeleteUser(c *gin.Context) {
|
||||
idStr := c.Query("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400, true)
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := db.DeleteUserById(uint(id)); err != nil {
|
||||
|
Reference in New Issue
Block a user