mirror of https://github.com/Xhofe/alist
feat(mediatrack): get real url (#2132)
* feat:get real url for mediatrack redirect token 一次有效,点击第二次就抛出了`400`错误。本次提交直接获取302后的真实链接返回前端 * add cache cache 60 Secondpull/2135/head
parent
5f79d665d9
commit
061c462f0b
|
@ -10,6 +10,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/drivers/base"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
|
@ -91,7 +92,21 @@ func (d *MediaTrack) Link(ctx context.Context, file model.Obj, args model.LinkAr
|
|||
}
|
||||
token := utils.Json.Get(body, "data", "token").ToString()
|
||||
url = "https://kayn.api.mediatrack.cn/v1/download/redirect?token=" + token
|
||||
return &model.Link{URL: url}, nil
|
||||
res, err := base.NoRedirectClient.R().Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(res.String())
|
||||
link := model.Link{
|
||||
URL: url,
|
||||
}
|
||||
log.Debugln("res code: ", res.StatusCode())
|
||||
if res.StatusCode() == 302 {
|
||||
link.URL = res.Header().Get("location")
|
||||
expired := time.Duration(60) * time.Second
|
||||
link.Expiration = &expired
|
||||
}
|
||||
return &link, nil
|
||||
}
|
||||
|
||||
func (d *MediaTrack) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
|
||||
|
|
Loading…
Reference in New Issue