Files
OpenList/server/controllers/down.go

34 lines
792 B
Go
Raw Normal View History

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