🎇 Pagination #257

This commit is contained in:
微凉
2022-01-04 21:21:27 +08:00
parent b60c7ecd9e
commit ef5cad1bf0
8 changed files with 98 additions and 43 deletions

View File

@ -30,6 +30,12 @@ func Hide(meta *model.Meta, files []model.File) []model.File {
func Pagination(files []model.File, pageNum, pageSize int) (int, []model.File) {
total := len(files)
switch conf.GetStr("load type") {
case "all":
return total, files
//case "pagination":
//
}
start := (pageNum - 1) * pageSize
if start > total {
return total, []model.File{}
@ -41,10 +47,16 @@ func Pagination(files []model.File, pageNum, pageSize int) (int, []model.File) {
return total, files[start:end]
}
func CheckPagination(req common.PathReq) error {
func CheckPagination(req *common.PathReq) error {
if conf.GetStr("loading type") == "all" {
return nil
}
if req.PageNum < 1 {
return errors.New("page_num can't be less than 1")
}
if req.PageSize == 0 {
req.PageSize = conf.GetInt("default page size", 30)
}
return nil
}
@ -89,7 +101,7 @@ func Path(c *gin.Context) {
})
return
}
err := CheckPagination(req)
err := CheckPagination(&req)
if err != nil {
common.ErrorResp(c, err, 400)
return