2021-12-07 07:56:43 +00:00
|
|
|
package common
|
2021-10-27 14:45:36 +00:00
|
|
|
|
|
|
|
import (
|
2021-11-17 14:19:11 +00:00
|
|
|
"github.com/Xhofe/alist/conf"
|
2021-10-27 14:45:36 +00:00
|
|
|
"github.com/Xhofe/alist/model"
|
|
|
|
"github.com/Xhofe/alist/utils"
|
2021-11-13 07:53:26 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2021-11-17 14:19:11 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-10-27 14:45:36 +00:00
|
|
|
)
|
|
|
|
|
2021-11-13 07:53:26 +00:00
|
|
|
func Login(c *gin.Context) {
|
|
|
|
SuccessResp(c)
|
2021-10-29 16:35:29 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 08:12:12 +00:00
|
|
|
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 {
|
2021-11-29 13:30:52 +00:00
|
|
|
if path == "/" {
|
2021-11-13 08:12:12 +00:00
|
|
|
return true
|
|
|
|
}
|
2021-11-29 13:09:16 +00:00
|
|
|
return CheckParent(utils.Dir(path), password)
|
2021-11-13 08:12:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-17 14:19:11 +00:00
|
|
|
|
2021-12-02 10:57:29 +00:00
|
|
|
func CheckDownLink(path string, passwordMd5 string, name string) bool {
|
2022-01-04 13:21:27 +00:00
|
|
|
if !conf.GetBool("check down link") {
|
2021-11-17 14:19:11 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
meta, err := model.GetMetaByPath(path)
|
|
|
|
log.Debugf("check down path: %s", path)
|
|
|
|
if err == nil {
|
|
|
|
log.Debugf("check down link: %s,%s", meta.Password, passwordMd5)
|
2021-12-08 02:33:26 +00:00
|
|
|
if meta.Password != "" && utils.SignWithPassword(name, meta.Password) != passwordMd5 {
|
2021-11-17 14:19:11 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
} else {
|
2022-01-04 13:21:27 +00:00
|
|
|
if !conf.GetBool("check parent folder") {
|
2021-11-17 14:19:11 +00:00
|
|
|
return true
|
|
|
|
}
|
2021-11-29 13:30:52 +00:00
|
|
|
if path == "/" {
|
2021-11-17 14:19:11 +00:00
|
|
|
return true
|
|
|
|
}
|
2021-12-02 10:57:29 +00:00
|
|
|
return CheckDownLink(utils.Dir(path), passwordMd5, name)
|
2021-11-17 14:19:11 +00:00
|
|
|
}
|
|
|
|
}
|