alist/server/middlewares/down.go

29 lines
606 B
Go
Raw Normal View History

2021-12-07 07:56:43 +00:00
package middlewares
import (
"fmt"
2021-12-07 12:16:34 +00:00
"github.com/Xhofe/alist/conf"
2021-12-07 07:56:43 +00: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 12:16:34 +00:00
sign := c.Query("sign")
2021-12-07 07:56:43 +00:00
rawPath := c.Param("path")
rawPath = utils.ParsePath(rawPath)
2021-12-07 12:16:34 +00:00
name := utils.Base(rawPath)
2021-12-08 02:33:26 +00:00
if sign == utils.SignWithToken(name, conf.Token) {
2021-12-19 09:10:20 +00:00
c.Set("sign", true)
2021-12-07 12:16:34 +00:00
c.Next()
return
}
2021-12-07 07:56:43 +00: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 09:10:20 +00:00
}