🚧 support proxy url

This commit is contained in:
微凉
2021-12-08 10:33:26 +08:00
parent b8698700ef
commit 190c8001a5
11 changed files with 45 additions and 13 deletions

View File

@ -35,7 +35,7 @@ func CheckDownLink(path string, passwordMd5 string, name string) bool {
log.Debugf("check down path: %s", path)
if err == nil {
log.Debugf("check down link: %s,%s", meta.Password, passwordMd5)
if meta.Password != "" && utils.Get16MD5Encode("alist"+meta.Password+name) != passwordMd5 {
if meta.Password != "" && utils.SignWithPassword(name, meta.Password) != passwordMd5 {
return false
}
return true

View File

@ -23,7 +23,7 @@ func Down(c *gin.Context) {
common.ErrorResp(c, err, 500)
return
}
if driver.Config().OnlyProxy {
if driver.Config().OnlyProxy || account.Proxy {
Proxy(c)
return
}
@ -45,6 +45,12 @@ func Proxy(c *gin.Context) {
common.ErrorResp(c, err, 500)
return
}
if account.ProxyUrl != "" {
name := utils.Base(rawPath)
link := fmt.Sprintf("%s%s?sign=%s", account.ProxyUrl, rawPath, utils.SignWithToken(name, conf.Token))
c.Redirect(302, link)
return
}
if !account.Proxy && utils.GetFileType(filepath.Ext(rawPath)) != conf.TEXT {
common.ErrorResp(c, fmt.Errorf("[%s] not allowed proxy", account.Name), 403)
return

View File

@ -11,7 +11,7 @@ import (
)
func Path(c *gin.Context) {
reqV,_ := c.Get("req")
reqV, _ := c.Get("req")
req := reqV.(common.PathReq)
if model.AccountsCount() > 1 && req.Path == "/" {
files, err := model.GetAccountFiles()
@ -66,7 +66,7 @@ func Path(c *gin.Context) {
}
func Link(c *gin.Context) {
reqV,_ := c.Get("req")
reqV, _ := c.Get("req")
req := reqV.(common.PathReq)
rawPath := req.Path
rawPath = utils.ParsePath(rawPath)
@ -81,6 +81,16 @@ func Link(c *gin.Context) {
common.ErrorResp(c, err, 500)
return
}
if driver.Config().NeedHeader {
common.SuccessResp(c, gin.H{
"url": link,
"header": gin.H{
"name": "Authorization",
"value": "Bearer " + account.AccessToken,
},
})
return
}
if driver.Config().OnlyProxy {
common.SuccessResp(c, gin.H{
"url": fmt.Sprintf("//%s/d%s", c.Request.Host, req.Path),
@ -95,7 +105,7 @@ func Link(c *gin.Context) {
}
func Preview(c *gin.Context) {
reqV,_ := c.Get("req")
reqV, _ := c.Get("req")
req := reqV.(common.PathReq)
rawPath := req.Path
rawPath = utils.ParsePath(rawPath)

View File

@ -13,7 +13,7 @@ func DownCheck(c *gin.Context) {
rawPath := c.Param("path")
rawPath = utils.ParsePath(rawPath)
name := utils.Base(rawPath)
if sign == utils.Get16MD5Encode(fmt.Sprintf("%s-%s", conf.Token, name)) {
if sign == utils.SignWithToken(name, conf.Token) {
c.Next()
return
}

View File

@ -21,7 +21,8 @@ func InitApiRouter(r *gin.Engine) {
path := public.Group("", middlewares.PathCheck, middlewares.CheckAccount)
path.POST("/path", controllers.Path)
path.POST("/preview", controllers.Preview)
path.POST("/link", controllers.Link)
//path.POST("/link",middlewares.Auth, controllers.Link)
public.GET("/settings", controllers.GetSettingsPublic)
}
@ -43,6 +44,8 @@ func InitApiRouter(r *gin.Engine) {
admin.POST("/meta/create", controllers.CreateMeta)
admin.POST("/meta/save", controllers.SaveMeta)
admin.DELETE("/meta", controllers.DeleteMeta)
admin.POST("/link", controllers.Link)
}
Static(r)
WebDav(r)

View File

@ -87,7 +87,7 @@ func GetPW(path string, name string) string {
meta, err := model.GetMetaByPath(path)
if err == nil {
if meta.Password != "" {
utils.Get16MD5Encode("alist" + meta.Password + name)
return utils.SignWithPassword(name, meta.Password)
}
return ""
} else {