🎨 change link interface
This commit is contained in:
@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -34,7 +35,7 @@ func Down(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
c.Redirect(302, link)
|
||||
c.Redirect(302, link.Url)
|
||||
return
|
||||
}
|
||||
|
||||
@ -71,7 +72,7 @@ func Proxy(c *gin.Context) {
|
||||
if account.Type == "Native" {
|
||||
// 对于名称为index.html的文件需要特殊处理
|
||||
if utils.Base(rawPath) == "index.html" {
|
||||
file, err := os.Open(link)
|
||||
file, err := os.Open(link.Url)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
@ -79,7 +80,7 @@ func Proxy(c *gin.Context) {
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
fileStat, err := os.Stat(link)
|
||||
fileStat, err := os.Stat(link.Url)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
@ -87,7 +88,7 @@ func Proxy(c *gin.Context) {
|
||||
http.ServeContent(c.Writer, c.Request, utils.Base(rawPath), fileStat.ModTime(), file)
|
||||
return
|
||||
}
|
||||
c.File(link)
|
||||
c.File(link.Url)
|
||||
return
|
||||
} else {
|
||||
if utils.GetFileType(filepath.Ext(rawPath)) == conf.TEXT {
|
||||
@ -97,13 +98,13 @@ func Proxy(c *gin.Context) {
|
||||
driver.Proxy(c, account)
|
||||
r := c.Request
|
||||
w := c.Writer
|
||||
target, err := url.Parse(link)
|
||||
target, err := url.Parse(link.Url)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
protocol := "http://"
|
||||
if strings.HasPrefix(link, "https://") {
|
||||
if strings.HasPrefix(link.Url, "https://") {
|
||||
protocol = "https://"
|
||||
}
|
||||
targetHost, err := url.Parse(fmt.Sprintf("%s%s", protocol, target.Host))
|
||||
@ -121,8 +122,8 @@ func init() {
|
||||
client.SetRetryCount(3)
|
||||
}
|
||||
|
||||
func Text(c *gin.Context, link string) {
|
||||
res, err := client.R().Get(link)
|
||||
func Text(c *gin.Context, link *base.Link) {
|
||||
res, err := client.R().Get(link.Url)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
|
@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
@ -42,7 +43,7 @@ func Path(c *gin.Context) {
|
||||
if driver.Config().OnlyProxy || account.Proxy {
|
||||
if account.ProxyUrl != "" {
|
||||
file.Url = fmt.Sprintf("%s%s?sign=%s", account.ProxyUrl, req.Path, utils.SignWithToken(file.Name, conf.Token))
|
||||
}else {
|
||||
} else {
|
||||
file.Url = fmt.Sprintf("//%s/d%s", c.Request.Host, req.Path)
|
||||
}
|
||||
}
|
||||
@ -71,7 +72,7 @@ func Path(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 返回真实的链接,非中转
|
||||
// 返回真实的链接,且携带头,只提供给中转程序使用
|
||||
func Link(c *gin.Context) {
|
||||
var req common.PathReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
@ -92,25 +93,13 @@ 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),
|
||||
if driver.Config().NoLink {
|
||||
common.SuccessResp(c, base.Link{
|
||||
Url: fmt.Sprintf("//%s/d%s?sign=%s", c.Request.Host, req.Path, utils.SignWithToken(utils.Base(rawPath), conf.Token)),
|
||||
})
|
||||
return
|
||||
} else {
|
||||
common.SuccessResp(c, gin.H{
|
||||
"url": link,
|
||||
})
|
||||
common.SuccessResp(c, link)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user