mirror of https://github.com/Xhofe/alist
fix(pikpak): captcha_token not refreshing correctly (#6788)
parent
a93937f80d
commit
049575b5a5
|
@ -76,11 +76,11 @@ func (d *PikPak) Init(ctx context.Context) (err error) {
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// 获取CaptchaToken
|
|
||||||
_ = d.RefreshCaptchaTokenAtLogin(GetAction(http.MethodGet, "https://api-drive.mypikpak.com/drive/v1/files"), d.Username)
|
|
||||||
|
|
||||||
// 获取用户ID
|
// 获取用户ID
|
||||||
_ = d.GetUserID(ctx)
|
_ = d.GetUserID()
|
||||||
|
|
||||||
|
// 获取CaptchaToken
|
||||||
|
_ = d.RefreshCaptchaTokenAtLogin(GetAction(http.MethodGet, "https://api-drive.mypikpak.com/drive/v1/files"), d.Common.UserID)
|
||||||
// 更新UserAgent
|
// 更新UserAgent
|
||||||
d.Common.UserAgent = BuildCustomUserAgent(d.Common.DeviceID, ClientID, PackageName, SdkVersion, ClientVersion, PackageName, d.Common.UserID)
|
d.Common.UserAgent = BuildCustomUserAgent(d.Common.DeviceID, ClientID, PackageName, SdkVersion, ClientVersion, PackageName, d.Common.UserID)
|
||||||
return nil
|
return nil
|
||||||
|
@ -320,17 +320,17 @@ func (d *PikPak) DeleteOfflineTasks(ctx context.Context, taskIDs []string, delet
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PikPak) GetUserID(ctx context.Context) error {
|
func (d *PikPak) GetUserID() error {
|
||||||
url := "https://api-drive.mypikpak.com/vip/v1/vip/info"
|
|
||||||
var resp VipInfo
|
token, err := d.oauth2Token.Token()
|
||||||
_, err := d.requestWithCaptchaToken(url, http.MethodGet, func(req *resty.Request) {
|
|
||||||
req.SetContext(ctx)
|
|
||||||
}, &resp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get user id : %w", err)
|
return err
|
||||||
}
|
}
|
||||||
if resp.Data.UserID != "" {
|
|
||||||
d.Common.SetUserID(resp.Data.UserID)
|
userID := token.Extra("sub").(string)
|
||||||
|
|
||||||
|
if userID != "" {
|
||||||
|
d.Common.SetUserID(userID)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,6 @@ import (
|
||||||
hash_extend "github.com/alist-org/alist/v3/pkg/utils/hash"
|
hash_extend "github.com/alist-org/alist/v3/pkg/utils/hash"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RespErr struct {
|
|
||||||
ErrorCode int `json:"error_code"`
|
|
||||||
Error string `json:"error"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Files struct {
|
type Files struct {
|
||||||
Files []File `json:"files"`
|
Files []File `json:"files"`
|
||||||
NextPageToken string `json:"next_page_token"`
|
NextPageToken string `json:"next_page_token"`
|
||||||
|
@ -174,7 +169,6 @@ type ErrResp struct {
|
||||||
ErrorCode int64 `json:"error_code"`
|
ErrorCode int64 `json:"error_code"`
|
||||||
ErrorMsg string `json:"error"`
|
ErrorMsg string `json:"error"`
|
||||||
ErrorDescription string `json:"error_description"`
|
ErrorDescription string `json:"error_description"`
|
||||||
// ErrorDetails interface{} `json:"error_details"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ErrResp) IsError() bool {
|
func (e *ErrResp) IsError() bool {
|
||||||
|
@ -199,37 +193,3 @@ type CaptchaTokenResponse struct {
|
||||||
ExpiresIn int64 `json:"expires_in"`
|
ExpiresIn int64 `json:"expires_in"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VipInfo struct {
|
|
||||||
Data struct {
|
|
||||||
Expire time.Time `json:"expire"`
|
|
||||||
ExtUserInfo struct {
|
|
||||||
UserRegion string `json:"userRegion"`
|
|
||||||
} `json:"extUserInfo"`
|
|
||||||
ExtType string `json:"ext_type"`
|
|
||||||
FeeRecord string `json:"fee_record"`
|
|
||||||
Restricted struct {
|
|
||||||
Result bool `json:"result"`
|
|
||||||
Content struct {
|
|
||||||
Text string `json:"text"`
|
|
||||||
Color string `json:"color"`
|
|
||||||
DeepLink string `json:"deepLink"`
|
|
||||||
} `json:"content"`
|
|
||||||
LearnMore struct {
|
|
||||||
Text string `json:"text"`
|
|
||||||
Color string `json:"color"`
|
|
||||||
DeepLink string `json:"deepLink"`
|
|
||||||
} `json:"learnMore"`
|
|
||||||
} `json:"restricted"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
UserID string `json:"user_id"`
|
|
||||||
VipItem []struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Expire time.Time `json:"expire"`
|
|
||||||
SurplusDay int `json:"surplus_day"`
|
|
||||||
} `json:"vipItem"`
|
|
||||||
} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -53,15 +52,15 @@ func (d *PikPak) request(url string, method string, callback base.ReqCallback, r
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
req.SetResult(resp)
|
req.SetResult(resp)
|
||||||
}
|
}
|
||||||
var e RespErr
|
var e ErrResp
|
||||||
req.SetError(&e)
|
req.SetError(&e)
|
||||||
res, err := req.Execute(method, url)
|
res, err := req.Execute(method, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.ErrorCode != 0 {
|
if e.IsError() {
|
||||||
return nil, errors.New(e.Error)
|
return nil, &e
|
||||||
}
|
}
|
||||||
return res.Body(), nil
|
return res.Body(), nil
|
||||||
}
|
}
|
||||||
|
@ -101,7 +100,7 @@ func (d *PikPak) requestWithCaptchaToken(url string, method string, callback bas
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return d.request(url, method, callback, resp)
|
return d.requestWithCaptchaToken(url, method, callback, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PikPak) getFiles(id string) ([]File, error) {
|
func (d *PikPak) getFiles(id string) ([]File, error) {
|
||||||
|
@ -264,7 +263,7 @@ func (c *Common) GetCaptchaSign() (timestamp, sign string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新验证码token
|
// refreshCaptchaToken 刷新CaptchaToken
|
||||||
func (d *PikPak) refreshCaptchaToken(action string, metas map[string]string) error {
|
func (d *PikPak) refreshCaptchaToken(action string, metas map[string]string) error {
|
||||||
param := CaptchaTokenRequest{
|
param := CaptchaTokenRequest{
|
||||||
Action: action,
|
Action: action,
|
||||||
|
|
Loading…
Reference in New Issue