🎇 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

@ -195,11 +195,11 @@ 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),
}).Get("https://cloud.189.cn/api/open/file/getFileDownloadUrl.action") }).Get("https://cloud.189.cn/api/open/file/getFileDownloadUrl.action")
if err != nil { if err != nil {
return "", err return "", err
} }
@ -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 {
@ -278,11 +282,11 @@ func (c Cloud189) Login(account *model.Account) error {
var loginResp LoginResp var loginResp LoginResp
res, err = client.R(). res, err = client.R().
SetHeaders(map[string]string{ SetHeaders(map[string]string{
"lt": lt, "lt": lt,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
"Referer": "https://open.e.189.cn/", "Referer": "https://open.e.189.cn/",
"accept": "application/json;charset=UTF-8", "accept": "application/json;charset=UTF-8",
}).SetFormData(map[string]string{ }).SetFormData(map[string]string{
"appKey": "cloud", "appKey": "cloud",
"accountType": "01", "accountType": "01",
"userName": "{RSA}" + userRsa, "userName": "{RSA}" + userRsa,
@ -361,17 +365,17 @@ 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",
"pageNum": strconv.Itoa(pageNum), "pageNum": strconv.Itoa(pageNum),
"mediaType": "0", "mediaType": "0",
"folderId": fileId, "folderId": fileId,
"iconOption": "5", "iconOption": "5",
"orderBy": account.OrderBy, "orderBy": account.OrderBy,
"descending": account.OrderDirection, "descending": account.OrderDirection,
}).Get("https://cloud.189.cn/api/open/file/listFiles.action") }).Get("https://cloud.189.cn/api/open/file/listFiles.action")
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -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
}),
)
}