Files
OpenList/server/middlewares/down.go

29 lines
606 B
Go
Raw Normal View History

2021-12-07 15:56:43 +08:00
package middlewares
import (
"fmt"
2021-12-07 20:16:34 +08:00
"github.com/Xhofe/alist/conf"
2021-12-07 15:56:43 +08:00
"github.com/Xhofe/alist/server/common"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
)
func DownCheck(c *gin.Context) {
2021-12-07 20:16:34 +08:00
sign := c.Query("sign")
2021-12-07 15:56:43 +08:00
rawPath := c.Param("path")
rawPath = utils.ParsePath(rawPath)
2021-12-07 20:16:34 +08:00
name := utils.Base(rawPath)
2021-12-08 10:33:26 +08:00
if sign == utils.SignWithToken(name, conf.Token) {
2021-12-19 17:10:20 +08:00
c.Set("sign", true)
2021-12-07 20:16:34 +08:00
c.Next()
return
}
2021-12-07 15:56:43 +08:00
pw := c.Query("pw")
if !common.CheckDownLink(utils.Dir(rawPath), pw, utils.Base(rawPath)) {
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
c.Abort()
return
}
c.Next()
2021-12-19 17:10:20 +08:00
}