feat(mediatrack): get real url (#2132)

* feat:get real url for mediatrack

redirect token 一次有效,点击第二次就抛出了`400`错误。本次提交直接获取302后的真实链接返回前端

* add cache

cache 60 Second
pull/2135/head
浅秋枫影 2022-10-27 15:26:08 +08:00 committed by GitHub
parent 5f79d665d9
commit 061c462f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -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 {