fix(189): login and get link (close #1182)

pull/1191/head
Noah Hsu 2022-05-31 16:03:54 +08:00
parent 323dad2a1c
commit f6be50f15a
2 changed files with 19 additions and 12 deletions

View File

@ -7,13 +7,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus"
"io" "io"
"math" "math"
"net/http" "net/http"
@ -21,6 +14,14 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus"
) )
var client189Map map[string]*resty.Client var client189Map map[string]*resty.Client
@ -98,6 +99,7 @@ func (driver Cloud189) Login(account *model.Account) error {
client.SetTimeout(base.DefaultTimeout) client.SetTimeout(base.DefaultTimeout)
client.SetRetryCount(3) client.SetRetryCount(3)
client.SetHeader("Referer", "https://cloud.189.cn/") client.SetHeader("Referer", "https://cloud.189.cn/")
client.SetHeader("User-Agent", base.UserAgent)
url := "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fmain.action" url := "https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https%3A%2F%2Fcloud.189.cn%2Fmain.action"
b := "" b := ""
lt := "" lt := ""

View File

@ -2,15 +2,16 @@ package _89
import ( import (
"fmt" "fmt"
"net/http"
"path/filepath"
"strings"
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http"
"path/filepath"
"strings"
) )
type Cloud189 struct{} type Cloud189 struct{}
@ -179,23 +180,27 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error { resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
})) }))
res, err := client.R().Get("https:" + resp.FileDownloadUrl) res, err := client.R().SetHeader("User-Agent", base.UserAgent).Get("https:" + resp.FileDownloadUrl)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Debugln(res.Status()) log.Debugln(res.Status())
log.Debugln(res.String())
link := base.Link{ link := base.Link{
Headers: []base.Header{ Headers: []base.Header{
{Name: "User-Agent", Value: base.UserAgent}, {Name: "User-Agent", Value: base.UserAgent},
//{Name: "Authorization", Value: ""}, //{Name: "Authorization", Value: ""},
}, },
} }
log.Debugln("first url:", resp.FileDownloadUrl)
if res.StatusCode() == 302 { if res.StatusCode() == 302 {
link.Url = res.Header().Get("location") link.Url = res.Header().Get("location")
res, err = client.R().Get(link.Url) log.Debugln("second url:", link.Url)
_, _ = client.R().Get(link.Url)
if res.StatusCode() == 302 { if res.StatusCode() == 302 {
link.Url = res.Header().Get("location") link.Url = res.Header().Get("location")
} }
log.Debugln("third url:", link.Url)
} else { } else {
link.Url = resp.FileDownloadUrl link.Url = resp.FileDownloadUrl
} }