|
package common |
|
|
|
import ( |
|
"path" |
|
"strings" |
|
|
|
"github.com/alist-org/alist/v3/internal/conf" |
|
"github.com/alist-org/alist/v3/internal/driver" |
|
"github.com/alist-org/alist/v3/internal/model" |
|
"github.com/alist-org/alist/v3/internal/op" |
|
"github.com/alist-org/alist/v3/pkg/utils" |
|
"github.com/dlclark/regexp2" |
|
) |
|
|
|
func IsStorageSignEnabled(rawPath string) bool { |
|
storage := op.GetBalancedStorage(rawPath) |
|
return storage != nil && storage.GetStorage().EnableSign |
|
} |
|
|
|
func CanWrite(meta *model.Meta, path string) bool { |
|
if meta == nil || !meta.Write { |
|
return false |
|
} |
|
return meta.WSub || meta.Path == path |
|
} |
|
|
|
func IsApply(metaPath, reqPath string, applySub bool) bool { |
|
if utils.PathEqual(metaPath, reqPath) { |
|
return true |
|
} |
|
return utils.IsSubPath(metaPath, reqPath) && applySub |
|
} |
|
|
|
func CanAccess(user *model.User, meta *model.Meta, reqPath string, password string) bool { |
|
|
|
if meta != nil && !user.CanSeeHides() && meta.Hide != "" && |
|
IsApply(meta.Path, path.Dir(reqPath), meta.HSub) { |
|
for _, hide := range strings.Split(meta.Hide, "\n") { |
|
re := regexp2.MustCompile(hide, regexp2.None) |
|
if isMatch, _ := re.MatchString(path.Base(reqPath)); isMatch { |
|
return false |
|
} |
|
} |
|
} |
|
|
|
if user.CanAccessWithoutPassword() { |
|
return true |
|
} |
|
|
|
if meta == nil || meta.Password == "" { |
|
return true |
|
} |
|
|
|
if !utils.PathEqual(meta.Path, reqPath) && !meta.PSub { |
|
return true |
|
} |
|
|
|
return meta.Password == password |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
func ShouldProxy(storage driver.Driver, filename string) bool { |
|
if storage.Config().MustProxy() || storage.GetStorage().WebProxy { |
|
return true |
|
} |
|
if utils.SliceContains(conf.SlicesMap[conf.ProxyTypes], utils.Ext(filename)) { |
|
return true |
|
} |
|
return false |
|
} |
|
|