🎇 resolved #160
This commit is contained in:
parent
725f5b0c55
commit
5db1ad4adf
@ -34,6 +34,7 @@
|
|||||||
- Onedrive/世纪互联
|
- Onedrive/世纪互联
|
||||||
- 天翼云盘
|
- 天翼云盘
|
||||||
- GoogleDrive
|
- GoogleDrive
|
||||||
|
- 123pan
|
||||||
- ...
|
- ...
|
||||||
|
|
||||||
### 如何使用
|
### 如何使用
|
||||||
|
@ -57,7 +57,7 @@ func InitSettings() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "text types",
|
Key: "text types",
|
||||||
Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp",
|
Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp,tsx",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Description: "text type extensions",
|
Description: "text type extensions",
|
||||||
},
|
},
|
||||||
@ -98,35 +98,48 @@ func InitSettings() {
|
|||||||
Key: "autoplay video",
|
Key: "autoplay video",
|
||||||
Value: "false",
|
Value: "false",
|
||||||
Type: "bool",
|
Type: "bool",
|
||||||
|
Group: model.PUBLIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "autoplay audio",
|
Key: "autoplay audio",
|
||||||
Value: "false",
|
Value: "false",
|
||||||
Type: "bool",
|
Type: "bool",
|
||||||
|
Group: model.PUBLIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "check parent folder",
|
Key: "check parent folder",
|
||||||
Value: "false",
|
Value: "false",
|
||||||
Type: "bool",
|
Type: "bool",
|
||||||
Description: "check parent folder password",
|
Description: "check parent folder password",
|
||||||
|
Group: model.PRIVATE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "customize style",
|
Key: "customize style",
|
||||||
Value: "",
|
Value: "",
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Description: "customize style, don't need add <style></style>",
|
Description: "customize style, don't need add <style></style>",
|
||||||
|
Group: model.PRIVATE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "customize script",
|
Key: "customize script",
|
||||||
Value: "",
|
Value: "",
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Description: "customize script, don't need add <script></script>",
|
Description: "customize script, don't need add <script></script>",
|
||||||
|
Group: model.PRIVATE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "animation",
|
Key: "animation",
|
||||||
Value: "true",
|
Value: "true",
|
||||||
Type: "bool",
|
Type: "bool",
|
||||||
Description: "when there are a lot of files, the animation will freeze when opening",
|
Description: "when there are a lot of files, the animation will freeze when opening",
|
||||||
|
Group: model.PUBLIC,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "check down link",
|
||||||
|
Value: "false",
|
||||||
|
Type: "bool",
|
||||||
|
Description: "check down link password, your link will be 'https://alist.com/d/filename?pw=xxx'",
|
||||||
|
Group: model.PUBLIC,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, v := range settings {
|
for _, v := range settings {
|
||||||
@ -139,4 +152,4 @@ func InitSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.LoadSettings()
|
model.LoadSettings()
|
||||||
}
|
}
|
||||||
|
@ -44,4 +44,5 @@ var (
|
|||||||
//CustomizeStyle string
|
//CustomizeStyle string
|
||||||
//CustomizeScript string
|
//CustomizeScript string
|
||||||
//Favicon string
|
//Favicon string
|
||||||
|
CheckDown bool
|
||||||
)
|
)
|
||||||
|
@ -61,6 +61,10 @@ func LoadSettings() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
conf.CheckParent = checkParent.Value == "true"
|
conf.CheckParent = checkParent.Value == "true"
|
||||||
}
|
}
|
||||||
|
checkDown,err := GetSettingByKey("check down link")
|
||||||
|
if err == nil {
|
||||||
|
conf.CheckDown = checkDown.Value == "true"
|
||||||
|
}
|
||||||
favicon, err := GetSettingByKey("favicon")
|
favicon, err := GetSettingByKey("favicon")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
//conf.Favicon = favicon.Value
|
//conf.Favicon = favicon.Value
|
||||||
|
@ -2,9 +2,11 @@ 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"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
@ -53,3 +55,26 @@ func CheckParent(path string, password string) bool {
|
|||||||
return CheckParent(filepath.Dir(path), password)
|
return CheckParent(filepath.Dir(path), password)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckDownLink(path string, passwordMd5 string) bool {
|
||||||
|
if !conf.CheckDown {
|
||||||
|
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)
|
||||||
|
if meta.Password != "" && utils.Get16MD5Encode(meta.Password) != passwordMd5 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
if !conf.CheckParent {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if path == "/" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return CheckDownLink(filepath.Dir(path), passwordMd5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,6 +21,11 @@ func Down(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
log.Debugf("down: %s", rawPath)
|
log.Debugf("down: %s", rawPath)
|
||||||
|
pw := c.Query("pw")
|
||||||
|
if !CheckDownLink(filepath.Dir(rawPath), pw) {
|
||||||
|
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
|
return
|
||||||
|
}
|
||||||
account, path, driver, err := ParsePath(rawPath)
|
account, path, driver, err := ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorResp(c, err, 500)
|
ErrorResp(c, err, 500)
|
||||||
@ -52,6 +57,11 @@ func Proxy(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
log.Debugf("proxy: %s", rawPath)
|
log.Debugf("proxy: %s", rawPath)
|
||||||
|
pw := c.Query("pw")
|
||||||
|
if !CheckDownLink(filepath.Dir(rawPath), pw) {
|
||||||
|
ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
|
return
|
||||||
|
}
|
||||||
account, path, driver, err := ParsePath(rawPath)
|
account, path, driver, err := ParsePath(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorResp(c, err, 500)
|
ErrorResp(c, err, 500)
|
||||||
@ -74,7 +84,7 @@ func Proxy(c *gin.Context) {
|
|||||||
Text(c, link)
|
Text(c, link)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
driver.Proxy(c,account)
|
driver.Proxy(c, account)
|
||||||
r := c.Request
|
r := c.Request
|
||||||
w := c.Writer
|
w := c.Writer
|
||||||
target, err := url.Parse(link)
|
target, err := url.Parse(link)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user