🐛 fix windows check parent password

pull/548/head
微凉 2021-11-29 21:09:16 +08:00
parent ffdd88ec66
commit 71b1517de7
5 changed files with 13 additions and 9 deletions

View File

@ -8,7 +8,6 @@ import (
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
"path/filepath"
)
func Auth(c *gin.Context) {
@ -52,7 +51,7 @@ func CheckParent(path string, password string) bool {
if path == "/" || path == "\\" {
return true
}
return CheckParent(filepath.Dir(path), password)
return CheckParent(utils.Dir(path), password)
}
}
@ -75,6 +74,6 @@ func CheckDownLink(path string, passwordMd5 string) bool {
if path == "/" || path == "\\" {
return true
}
return CheckDownLink(filepath.Dir(path), passwordMd5)
return CheckDownLink(utils.Dir(path), passwordMd5)
}
}

View File

@ -18,7 +18,7 @@ func Down(c *gin.Context) {
rawPath = utils.ParsePath(rawPath)
log.Debugf("down: %s", rawPath)
pw := c.Query("pw")
if !CheckDownLink(filepath.Dir(rawPath), pw) {
if !CheckDownLink(utils.Dir(rawPath), pw) {
ErrorResp(c, fmt.Errorf("wrong password"), 401)
return
}
@ -50,7 +50,7 @@ func Proxy(c *gin.Context) {
rawPath = utils.ParsePath(rawPath)
log.Debugf("proxy: %s", rawPath)
pw := c.Query("pw")
if !CheckDownLink(filepath.Dir(rawPath), pw) {
if !CheckDownLink(utils.Dir(rawPath), pw) {
ErrorResp(c, fmt.Errorf("wrong password"), 401)
return
}

View File

@ -7,7 +7,6 @@ import (
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"path/filepath"
"strings"
)
@ -32,7 +31,7 @@ func Path(c *gin.Context) {
}
// TODO hide or ignore?
} else if conf.CheckParent {
if !CheckParent(filepath.Dir(req.Path), req.Password) {
if !CheckParent(utils.Dir(req.Path), req.Password) {
ErrorResp(c, fmt.Errorf("wrong password"), 401)
return
}

View File

@ -97,7 +97,7 @@ func GetPW(path string) string {
if path == "/" || path == "\\" {
return ""
}
return GetPW(filepath.Dir(path))
return GetPW(utils.Dir(path))
}
}
@ -119,7 +119,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 {
pw := GetPW(filepath.Dir(rawPath))
pw := GetPW(utils.Dir(rawPath))
link += "?pw" + pw
}
} else {

View File

@ -94,4 +94,10 @@ func RemoveLastSlash(path string) string {
return strings.TrimSuffix(path, "/")
}
return path
}
func Dir(path string) string {
path = ParsePath(path)
idx := strings.LastIndex(path, "/")
return path[:idx]
}