mirror of https://github.com/Xhofe/alist
🐛 fix windows check parent password
parent
ffdd88ec66
commit
71b1517de7
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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]
|
||||
}
|
Loading…
Reference in New Issue