🎇 get 189 redirect url
This commit is contained in:
parent
da74e29b26
commit
4466cb19a5
@ -195,7 +195,7 @@ func (c Cloud189) Link(path string, account *model.Account) (string, error) {
|
|||||||
var e Cloud189Error
|
var e Cloud189Error
|
||||||
var resp Cloud189Down
|
var resp Cloud189Down
|
||||||
_, err = client.R().SetResult(&resp).SetError(&e).
|
_, err = client.R().SetResult(&resp).SetError(&e).
|
||||||
SetHeader("Accept","application/json;charset=UTF-8").
|
SetHeader("Accept", "application/json;charset=UTF-8").
|
||||||
SetQueryParams(map[string]string{
|
SetQueryParams(map[string]string{
|
||||||
"noCache": random(),
|
"noCache": random(),
|
||||||
"fileId": strconv.FormatInt(file.Id, 10),
|
"fileId": strconv.FormatInt(file.Id, 10),
|
||||||
@ -215,6 +215,10 @@ func (c Cloud189) Link(path string, account *model.Account) (string, error) {
|
|||||||
if resp.ResCode != 0 {
|
if resp.ResCode != 0 {
|
||||||
return "", fmt.Errorf(resp.ResMessage)
|
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
|
return resp.FileDownloadUrl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,13 +237,13 @@ func init() {
|
|||||||
client189Map = make(map[string]*resty.Client, 0)
|
client189Map = make(map[string]*resty.Client, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// refer to PanIndex
|
|
||||||
type LoginResp struct {
|
type LoginResp struct {
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
Result int `json:"result"`
|
Result int `json:"result"`
|
||||||
ToUrl string `json:"toUrl"`
|
ToUrl string `json:"toUrl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Login refer to PanIndex
|
||||||
func (c Cloud189) Login(account *model.Account) error {
|
func (c Cloud189) Login(account *model.Account) error {
|
||||||
client, ok := client189Map[account.Name]
|
client, ok := client189Map[account.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -361,7 +365,7 @@ func (c Cloud189) GetFiles(fileId string, account *model.Account) ([]Cloud189Fil
|
|||||||
var e Cloud189Error
|
var e Cloud189Error
|
||||||
var resp Cloud189Files
|
var resp Cloud189Files
|
||||||
_, err := client.R().SetResult(&resp).SetError(&e).
|
_, err := client.R().SetResult(&resp).SetError(&e).
|
||||||
SetHeader("Accept","application/json;charset=UTF-8").
|
SetHeader("Accept", "application/json;charset=UTF-8").
|
||||||
SetQueryParams(map[string]string{
|
SetQueryParams(map[string]string{
|
||||||
"noCache": random(),
|
"noCache": random(),
|
||||||
"pageSize": "60",
|
"pageSize": "60",
|
||||||
|
@ -3,6 +3,8 @@ package drivers
|
|||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Driver interface {
|
type Driver interface {
|
||||||
@ -53,3 +55,13 @@ func GetDrivers() map[string][]Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Json map[string]interface{}
|
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
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user