feat(thunderBrowser): add automatically generate UserAgent (#6692)
This commit is contained in:
@ -2,10 +2,10 @@ package thunder_browser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/drivers/base"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/op"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
@ -53,33 +53,17 @@ func (x *ThunderBrowser) Init(ctx context.Context) (err error) {
|
||||
if x.XunLeiBrowserCommon == nil {
|
||||
x.XunLeiBrowserCommon = &XunLeiBrowserCommon{
|
||||
Common: &Common{
|
||||
client: base.NewRestyClient(),
|
||||
Algorithms: []string{
|
||||
"x+I5XiTByg",
|
||||
"6QU1x5DqGAV3JKg6h",
|
||||
"VI1vL1WXr7st0es",
|
||||
"n+/3yhlrnKs4ewhLgZhZ5ITpt554",
|
||||
"UOip2PE7BLIEov/ZX6VOnsz",
|
||||
"Q70h9lpViNCOC8sGVkar9o22LhBTjfP",
|
||||
"IVHFuB1JcMlaZHnW",
|
||||
"bKE",
|
||||
"HZRbwxOiQx+diNopi6Nu",
|
||||
"fwyasXgYL3rP314331b",
|
||||
"LWxXAiSW4",
|
||||
"UlWIjv1HGrC6Ngmt4Nohx",
|
||||
"FOa+Lc0bxTDpTwIh2",
|
||||
"0+RY",
|
||||
"xmRVMqokHHpvsiH0",
|
||||
},
|
||||
client: base.NewRestyClient(),
|
||||
Algorithms: Algorithms,
|
||||
DeviceID: utils.GetMD5EncodeStr(x.Username + x.Password),
|
||||
ClientID: "ZUBzD9J_XPXfn7f7",
|
||||
ClientSecret: "yESVmHecEe6F0aou69vl-g",
|
||||
ClientVersion: "1.0.7.1938",
|
||||
PackageName: "com.xunlei.browser",
|
||||
UserAgent: "ANDROID-com.xunlei.browser/1.0.7.1938 netWorkType/5G appid/22062 deviceName/Xiaomi_M2004j7ac deviceModel/M2004J7AC OSVersion/12 protocolVersion/301 platformVersion/10 sdkVersion/233100 Oauth2Client/0.9 (Linux 4_14_186-perf-gddfs8vbb238b) (JAVA 0)",
|
||||
DownloadUserAgent: "AndroidDownloadManager/12 (Linux; U; Android 12; M2004J7AC Build/SP1A.210812.016)",
|
||||
ClientID: ClientID,
|
||||
ClientSecret: ClientSecret,
|
||||
ClientVersion: ClientVersion,
|
||||
PackageName: PackageName,
|
||||
UserAgent: BuildCustomUserAgent(utils.GetMD5EncodeStr(x.Username+x.Password), PackageName, SdkVersion, ClientVersion, PackageName),
|
||||
DownloadUserAgent: DownloadUserAgent,
|
||||
UseVideoUrl: x.UseVideoUrl,
|
||||
|
||||
RemoveWay: x.Addition.RemoveWay,
|
||||
refreshCTokenCk: func(token string) {
|
||||
x.CaptchaToken = token
|
||||
op.MustSaveDriverStorage(x)
|
||||
@ -107,6 +91,9 @@ func (x *ThunderBrowser) Init(ctx context.Context) (err error) {
|
||||
if ctoekn != "" {
|
||||
x.SetCaptchaToken(ctoekn)
|
||||
}
|
||||
if x.DeviceID == "" {
|
||||
x.SetDeviceID(utils.GetMD5EncodeStr(x.Username + x.Password))
|
||||
}
|
||||
x.XunLeiBrowserCommon.UseVideoUrl = x.UseVideoUrl
|
||||
x.Addition.RootFolderID = x.RootFolderID
|
||||
// 防止重复登录
|
||||
@ -170,21 +157,36 @@ func (x *ThunderBrowserExpert) Init(ctx context.Context) (err error) {
|
||||
x.XunLeiBrowserCommon = &XunLeiBrowserCommon{
|
||||
Common: &Common{
|
||||
client: base.NewRestyClient(),
|
||||
|
||||
DeviceID: func() string {
|
||||
if len(x.DeviceID) != 32 {
|
||||
return utils.GetMD5EncodeStr(x.DeviceID)
|
||||
if x.LoginType == "user" {
|
||||
return utils.GetMD5EncodeStr(x.Username + x.Password)
|
||||
}
|
||||
return utils.GetMD5EncodeStr(x.ExpertAddition.RefreshToken)
|
||||
}
|
||||
return x.DeviceID
|
||||
}(),
|
||||
ClientID: x.ClientID,
|
||||
ClientSecret: x.ClientSecret,
|
||||
ClientVersion: x.ClientVersion,
|
||||
PackageName: x.PackageName,
|
||||
UserAgent: x.UserAgent,
|
||||
DownloadUserAgent: x.DownloadUserAgent,
|
||||
UseVideoUrl: x.UseVideoUrl,
|
||||
|
||||
ClientID: x.ClientID,
|
||||
ClientSecret: x.ClientSecret,
|
||||
ClientVersion: x.ClientVersion,
|
||||
PackageName: x.PackageName,
|
||||
UserAgent: func() string {
|
||||
if x.ExpertAddition.UserAgent != "" {
|
||||
return x.ExpertAddition.UserAgent
|
||||
}
|
||||
if x.LoginType == "user" {
|
||||
return BuildCustomUserAgent(utils.GetMD5EncodeStr(x.Username+x.Password), x.PackageName, SdkVersion, x.ClientVersion, x.PackageName)
|
||||
}
|
||||
return BuildCustomUserAgent(utils.GetMD5EncodeStr(x.ExpertAddition.RefreshToken), x.PackageName, SdkVersion, x.ClientVersion, x.PackageName)
|
||||
}(),
|
||||
DownloadUserAgent: func() string {
|
||||
if x.ExpertAddition.DownloadUserAgent != "" {
|
||||
return x.ExpertAddition.DownloadUserAgent
|
||||
}
|
||||
return DownloadUserAgent
|
||||
}(),
|
||||
UseVideoUrl: x.UseVideoUrl,
|
||||
RemoveWay: x.ExpertAddition.RemoveWay,
|
||||
refreshCTokenCk: func(token string) {
|
||||
x.CaptchaToken = token
|
||||
op.MustSaveDriverStorage(x)
|
||||
@ -192,8 +194,21 @@ func (x *ThunderBrowserExpert) Init(ctx context.Context) (err error) {
|
||||
},
|
||||
}
|
||||
|
||||
if x.CaptchaToken != "" {
|
||||
x.SetCaptchaToken(x.CaptchaToken)
|
||||
if x.ExpertAddition.CaptchaToken != "" {
|
||||
x.SetCaptchaToken(x.ExpertAddition.CaptchaToken)
|
||||
op.MustSaveDriverStorage(x)
|
||||
}
|
||||
if x.Common.DeviceID != "" {
|
||||
x.ExpertAddition.DeviceID = x.Common.DeviceID
|
||||
op.MustSaveDriverStorage(x)
|
||||
}
|
||||
if x.Common.UserAgent != "" {
|
||||
x.ExpertAddition.UserAgent = x.Common.UserAgent
|
||||
op.MustSaveDriverStorage(x)
|
||||
}
|
||||
if x.Common.DownloadUserAgent != "" {
|
||||
x.ExpertAddition.DownloadUserAgent = x.Common.DownloadUserAgent
|
||||
op.MustSaveDriverStorage(x)
|
||||
}
|
||||
x.XunLeiBrowserCommon.UseVideoUrl = x.UseVideoUrl
|
||||
x.ExpertAddition.RootFolderID = x.RootFolderID
|
||||
@ -488,7 +503,8 @@ func (xc *XunLeiBrowserCommon) Remove(ctx context.Context, obj model.Obj) error
|
||||
}
|
||||
}
|
||||
|
||||
if xc.RemoveWay == "delete" && obj.GetPath() == ThunderDriveFileID {
|
||||
// 先判断是否是特殊情况
|
||||
if obj.GetPath() == ThunderDriveFileID {
|
||||
_, err := xc.Request(FILE_API_URL+"/{fileID}/trash", http.MethodPatch, func(r *resty.Request) {
|
||||
r.SetContext(ctx)
|
||||
r.SetPathParam("fileID", obj.GetID())
|
||||
@ -503,12 +519,20 @@ func (xc *XunLeiBrowserCommon) Remove(ctx context.Context, obj model.Obj) error
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := xc.Request(FILE_API_URL+":batchTrash", http.MethodPost, func(r *resty.Request) {
|
||||
r.SetContext(ctx)
|
||||
r.SetBody(&js)
|
||||
}, nil)
|
||||
return err
|
||||
|
||||
// 根据用户选择的删除方式进行删除
|
||||
if xc.RemoveWay == "delete" {
|
||||
_, err := xc.Request(FILE_API_URL+":batchDelete", http.MethodPost, func(r *resty.Request) {
|
||||
r.SetContext(ctx)
|
||||
r.SetBody(&js)
|
||||
}, nil)
|
||||
return err
|
||||
} else {
|
||||
_, err := xc.Request(FILE_API_URL+":batchTrash", http.MethodPost, func(r *resty.Request) {
|
||||
r.SetContext(ctx)
|
||||
r.SetBody(&js)
|
||||
}, nil)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func (xc *XunLeiBrowserCommon) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
|
||||
@ -756,7 +780,7 @@ func (xc *XunLeiBrowserCommon) RefreshToken(refreshToken string) (*TokenResp, er
|
||||
}
|
||||
|
||||
if resp.RefreshToken == "" {
|
||||
return nil, errs.EmptyToken
|
||||
return nil, errors.New("refresh token is empty")
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
@ -775,7 +799,7 @@ func (xc *XunLeiBrowserCommon) GetSafeAccessToken(safePassword string) (string,
|
||||
}
|
||||
|
||||
if resp.Token == "" {
|
||||
return "", errs.EmptyToken
|
||||
return "", errors.New("SafePassword is incorrect ")
|
||||
}
|
||||
return resp.Token, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user