alist/server/controllers/down.go

34 lines
792 B
Go
Raw Normal View History

2021-12-07 07:56:43 +00:00
package controllers
2021-10-26 14:28:37 +00:00
2021-10-28 14:50:09 +00:00
import (
2022-02-24 08:25:17 +00:00
"github.com/Xhofe/alist/conf"
2021-12-09 11:24:34 +00:00
"github.com/Xhofe/alist/drivers/base"
2021-12-07 07:56:43 +00:00
"github.com/Xhofe/alist/server/common"
2021-10-28 14:50:09 +00:00
"github.com/Xhofe/alist/utils"
2021-11-13 07:53:26 +00:00
"github.com/gin-gonic/gin"
2021-10-28 14:50:09 +00:00
log "github.com/sirupsen/logrus"
2022-02-24 08:25:17 +00:00
"path"
2021-10-28 14:50:09 +00:00
)
2021-10-26 14:28:37 +00:00
2021-11-13 07:53:26 +00:00
func Down(c *gin.Context) {
rawPath := c.Param("path")
2021-10-28 14:50:09 +00:00
rawPath = utils.ParsePath(rawPath)
2021-11-09 08:03:04 +00:00
log.Debugf("down: %s", rawPath)
2022-02-24 08:25:17 +00:00
account, path_, driver, err := common.ParsePath(rawPath)
2021-10-26 14:28:37 +00:00
if err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 500)
2021-11-13 07:53:26 +00:00
return
2021-10-26 14:28:37 +00:00
}
2022-02-24 08:25:17 +00:00
if driver.Config().OnlyProxy || account.Proxy || utils.IsContain(conf.DProxyTypes, path.Ext(rawPath)) {
2021-11-17 09:20:57 +00:00
Proxy(c)
return
}
2022-02-24 08:25:17 +00:00
link, err := driver.Link(base.Args{Path: path_, IP: c.ClientIP()}, account)
2021-10-26 14:28:37 +00:00
if err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 500)
2021-11-13 07:53:26 +00:00
return
2021-10-26 14:28:37 +00:00
}
2021-12-09 11:24:34 +00:00
c.Redirect(302, link.Url)
2021-12-07 07:56:43 +00:00
return
2021-10-26 14:28:37 +00:00
}