mirror of https://github.com/Xhofe/alist
✨ check parent folder password
parent
a73501463f
commit
959ef620fb
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Auth(c *gin.Context) {
|
func Auth(c *gin.Context) {
|
||||||
|
@ -37,3 +38,18 @@ func CheckAccount(c *gin.Context) {
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckParent(path string, password string) bool {
|
||||||
|
meta, err := model.GetMetaByPath(path)
|
||||||
|
if err == nil {
|
||||||
|
if meta.Password != "" && meta.Password != password {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
if path == "/" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return CheckParent(filepath.Dir(path), password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,6 +32,12 @@ func Path(c *gin.Context) {
|
||||||
}
|
}
|
||||||
// TODO hide or ignore?
|
// TODO hide or ignore?
|
||||||
}
|
}
|
||||||
|
if conf.CheckParent {
|
||||||
|
if !CheckParent(filepath.Dir(req.Path), req.Password) {
|
||||||
|
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
if model.AccountsCount() > 1 && req.Path == "/" {
|
if model.AccountsCount() > 1 && req.Path == "/" {
|
||||||
files, err := model.GetAccountFiles()
|
files, err := model.GetAccountFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue