Files
OpenList/server/middlewares/down.go

28 lines
590 B
Go
Raw Normal View History

2021-12-07 15:56:43 +08:00
package middlewares
import (
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)) {
2022-01-13 21:23:27 +08:00
common.ErrorStrResp(c, "Wrong password", 401)
2021-12-07 15:56:43 +08:00
c.Abort()
return
}
c.Next()
2021-12-19 17:10:20 +08:00
}