chore: rename some request param
This commit is contained in:
parent
8cd05275f0
commit
02e2c809a8
@ -1,8 +1,8 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
type PageReq struct {
|
type PageReq struct {
|
||||||
PageIndex int `json:"page_index" form:"page_index"`
|
Page int `json:"page_index" form:"page"`
|
||||||
PageSize int `json:"page_size" form:"page_size"`
|
PerPage int `json:"page_size" form:"per_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const MaxUint = ^uint(0)
|
const MaxUint = ^uint(0)
|
||||||
@ -11,10 +11,10 @@ const MaxInt = int(MaxUint >> 1)
|
|||||||
const MinInt = -MaxInt - 1
|
const MinInt = -MaxInt - 1
|
||||||
|
|
||||||
func (p *PageReq) Validate() {
|
func (p *PageReq) Validate() {
|
||||||
if p.PageIndex < 1 {
|
if p.Page < 1 {
|
||||||
p.PageIndex = 1
|
p.Page = 1
|
||||||
}
|
}
|
||||||
if p.PageSize < 1 {
|
if p.PerPage < 1 {
|
||||||
p.PageSize = MaxInt
|
p.PerPage = MaxInt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,9 +230,9 @@ func FsPut(c *gin.Context) {
|
|||||||
common.SuccessResp(c)
|
common.SuccessResp(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link return real link, just for proxy program, it may contain cookie
|
// Link return real link, just for proxy program, it may contain cookie, so just allowed for admin
|
||||||
func Link(c *gin.Context) {
|
func Link(c *gin.Context) {
|
||||||
var req FsGetOrLinkReq
|
var req MkdirOrLinkReq
|
||||||
if err := c.ShouldBind(&req); err != nil {
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
|
@ -153,7 +153,7 @@ func canAccess(user *model.User, meta *model.Meta, path string, password string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
|
func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
|
||||||
pageIndex, pageSize := req.PageIndex, req.PageSize
|
pageIndex, pageSize := req.Page, req.PerPage
|
||||||
total := len(objs)
|
total := len(objs)
|
||||||
start := (pageIndex - 1) * pageSize
|
start := (pageIndex - 1) * pageSize
|
||||||
if start > total {
|
if start > total {
|
||||||
@ -190,7 +190,7 @@ func toObjResp(objs []model.Obj) []ObjResp {
|
|||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
type FsGetOrLinkReq struct {
|
type FsGetReq struct {
|
||||||
Path string `json:"path" form:"path"`
|
Path string `json:"path" form:"path"`
|
||||||
Password string `json:"password" form:"password"`
|
Password string `json:"password" form:"password"`
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ type FsGetResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FsGet(c *gin.Context) {
|
func FsGet(c *gin.Context) {
|
||||||
var req FsGetOrLinkReq
|
var req FsGetReq
|
||||||
if err := c.ShouldBind(&req); err != nil {
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
|
@ -22,7 +22,7 @@ func ListMetas(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
req.Validate()
|
req.Validate()
|
||||||
log.Debugf("%+v", req)
|
log.Debugf("%+v", req)
|
||||||
metas, total, err := db.GetMetas(req.PageIndex, req.PageSize)
|
metas, total, err := db.GetMetas(req.Page, req.PerPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500, true)
|
common.ErrorResp(c, err, 500, true)
|
||||||
return
|
return
|
||||||
|
@ -19,7 +19,7 @@ func ListStorages(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
req.Validate()
|
req.Validate()
|
||||||
log.Debugf("%+v", req)
|
log.Debugf("%+v", req)
|
||||||
storages, total, err := db.GetStorages(req.PageIndex, req.PageSize)
|
storages, total, err := db.GetStorages(req.Page, req.PerPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
|
@ -18,7 +18,7 @@ func ListUsers(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
req.Validate()
|
req.Validate()
|
||||||
log.Debugf("%+v", req)
|
log.Debugf("%+v", req)
|
||||||
users, total, err := db.GetUsers(req.PageIndex, req.PageSize)
|
users, total, err := db.GetUsers(req.Page, req.PerPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500, true)
|
common.ErrorResp(c, err, 500, true)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user