🎇 support add another alist

This commit is contained in:
微凉
2021-12-07 20:16:34 +08:00
parent 74d8fa3919
commit 985b81826f
8 changed files with 37 additions and 17 deletions

View File

@ -2,25 +2,24 @@ package middlewares
import (
"fmt"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/server/common"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func Auth(c *gin.Context) {
token := c.GetHeader("Authorization")
password, err := model.GetSettingByKey("password")
if err != nil {
if err == gorm.ErrRecordNotFound {
common.ErrorResp(c, fmt.Errorf("password not set"), 400)
return
}
common.ErrorResp(c, err, 500)
return
}
if token != utils.GetMD5Encode(password.Value) {
//password, err := model.GetSettingByKey("password")
//if err != nil {
// if err == gorm.ErrRecordNotFound {
// common.ErrorResp(c, fmt.Errorf("password not set"), 400)
// return
// }
// common.ErrorResp(c, err, 500)
// return
//}
//if token != utils.GetMD5Encode(password.Value) {
if token != conf.Token {
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
return
}

View File

@ -2,14 +2,21 @@ package middlewares
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/server/common"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
)
func DownCheck(c *gin.Context) {
sign := c.Query("sign")
rawPath := c.Param("path")
rawPath = utils.ParsePath(rawPath)
name := utils.Base(rawPath)
if sign == utils.Get16MD5Encode(fmt.Sprintf("%s-%s", conf.Token, name)) {
c.Next()
return
}
pw := c.Query("pw")
if !common.CheckDownLink(utils.Dir(rawPath), pw, utils.Base(rawPath)) {
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)

View File

@ -17,6 +17,11 @@ func PathCheck(c *gin.Context) {
}
req.Path = utils.ParsePath(req.Path)
c.Set("req",req)
token := c.GetHeader("Authorization")
if token == conf.Token {
c.Next()
return
}
meta, err := model.GetMetaByPath(req.Path)
if err == nil {
if meta.Password != "" && meta.Password != req.Password {