🎇 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

@ -28,7 +28,7 @@ func CheckParent(path string, password string) bool {
}
func CheckDownLink(path string, passwordMd5 string, name string) bool {
if !conf.CheckDown {
if !conf.GetBool("check down link") {
return true
}
meta, err := model.GetMetaByPath(path)
@ -40,7 +40,7 @@ func CheckDownLink(path string, passwordMd5 string, name string) bool {
}
return true
} else {
if !conf.CheckParent {
if !conf.GetBool("check parent folder") {
return true
}
if path == "/" {

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

View File

@ -16,7 +16,7 @@ func PathCheck(c *gin.Context) {
return
}
req.Path = utils.ParsePath(req.Path)
c.Set("req",req)
c.Set("req", req)
token := c.GetHeader("Authorization")
if token == conf.Token {
c.Next()
@ -29,7 +29,7 @@ func PathCheck(c *gin.Context) {
c.Abort()
return
}
} else if conf.CheckParent {
} else if conf.GetBool("check parent folder") {
if !common.CheckParent(utils.Dir(req.Path), req.Password) {
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
c.Abort()
@ -37,4 +37,4 @@ func PathCheck(c *gin.Context) {
}
}
c.Next()
}
}

View File

@ -49,11 +49,14 @@ func WebDAVAuth(c *gin.Context) {
c.Abort()
return
}
if conf.DavUsername == username && conf.DavPassword == password {
if conf.GetStr("WebDAV username") == username && conf.GetStr("WebDAV password") == password {
c.Next()
return
}
if (conf.VisitorDavUsername == username && conf.VisitorDavPassword == password) || (conf.VisitorDavUsername == "" && conf.VisitorDavPassword == "") {
if (conf.GetStr("Visitor WebDAV username") == username &&
conf.GetStr("Visitor WebDAV password") == password) ||
(conf.GetStr("Visitor WebDAV username") == "" &&
conf.GetStr("Visitor WebDAV password") == "") {
if !utils.IsContain([]string{"PUT", "DELETE", "PROPPATCH", "MKCOL", "COPY", "MOVE"}, c.Request.Method) {
c.Next()
return

View File

@ -95,7 +95,7 @@ func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
}
if driver.Config().OnlyProxy || account.WebdavProxy {
link = fmt.Sprintf("%s://%s/p%s", protocol, r.Host, rawPath)
if conf.CheckDown {
if conf.GetBool("check down link") {
sign := utils.SignWithToken(utils.Base(rawPath), conf.Token)
link += "?sign" + sign
}