🎇 get 189 redirect url

This commit is contained in:
微凉 2021-11-15 20:15:25 +08:00
parent da74e29b26
commit 4466cb19a5
2 changed files with 36 additions and 20 deletions

View File

@ -215,6 +215,10 @@ func (c Cloud189) Link(path string, account *model.Account) (string, error) {
if resp.ResCode != 0 {
return "", fmt.Errorf(resp.ResMessage)
}
res, err := noRedirectClient.R().Get(resp.FileDownloadUrl)
if res.StatusCode() == 302 {
return res.Header().Get("location"), nil
}
return resp.FileDownloadUrl, nil
}
@ -233,13 +237,13 @@ func init() {
client189Map = make(map[string]*resty.Client, 0)
}
// refer to PanIndex
type LoginResp struct {
Msg string `json:"msg"`
Result int `json:"result"`
ToUrl string `json:"toUrl"`
}
// Login refer to PanIndex
func (c Cloud189) Login(account *model.Account) error {
client, ok := client189Map[account.Name]
if !ok {

View File

@ -3,6 +3,8 @@ package drivers
import (
"github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
"net/http"
)
type Driver interface {
@ -53,3 +55,13 @@ func GetDrivers() map[string][]Item {
}
type Json map[string]interface{}
var noRedirectClient *resty.Client
func init() {
noRedirectClient = resty.New().SetRedirectPolicy(
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}),
)
}