fix: allow force root while fetch dirs (close #1671)

pull/1831/head
Noah Hsu 2022-09-14 19:57:39 +08:00
parent b197322cd8
commit 66b2562d03
1 changed files with 11 additions and 3 deletions

View File

@ -28,6 +28,7 @@ type ListReq struct {
type DirReq struct { type DirReq 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"`
ForceRoot bool `json:"force_root" form:"force_root"`
} }
type ObjResp struct { type ObjResp struct {
@ -93,7 +94,14 @@ func FsDirs(c *gin.Context) {
return return
} }
user := c.MustGet("user").(*model.User) user := c.MustGet("user").(*model.User)
if req.ForceRoot {
if !user.IsAdmin() {
common.ErrorStrResp(c, "Permission denied", 403)
return
}
} else {
req.Path = stdpath.Join(user.BasePath, req.Path) req.Path = stdpath.Join(user.BasePath, req.Path)
}
meta, err := db.GetNearestMeta(req.Path) meta, err := db.GetNearestMeta(req.Path)
if err != nil { if err != nil {
if !errors.Is(errors.Cause(err), errs.MetaNotFound) { if !errors.Is(errors.Cause(err), errs.MetaNotFound) {