diff --git a/drivers/pikpak/driver.go b/drivers/pikpak/driver.go index 23198455a74..1d086e0a5cf 100644 --- a/drivers/pikpak/driver.go +++ b/drivers/pikpak/driver.go @@ -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 - _ = d.GetUserID(ctx) + _ = d.GetUserID() + + // 获取CaptchaToken + _ = d.RefreshCaptchaTokenAtLogin(GetAction(http.MethodGet, "https://api-drive.mypikpak.com/drive/v1/files"), d.Common.UserID) // 更新UserAgent d.Common.UserAgent = BuildCustomUserAgent(d.Common.DeviceID, ClientID, PackageName, SdkVersion, ClientVersion, PackageName, d.Common.UserID) return nil @@ -320,17 +320,17 @@ func (d *PikPak) DeleteOfflineTasks(ctx context.Context, taskIDs []string, delet return nil } -func (d *PikPak) GetUserID(ctx context.Context) error { - url := "https://api-drive.mypikpak.com/vip/v1/vip/info" - var resp VipInfo - _, err := d.requestWithCaptchaToken(url, http.MethodGet, func(req *resty.Request) { - req.SetContext(ctx) - }, &resp) +func (d *PikPak) GetUserID() error { + + token, err := d.oauth2Token.Token() 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 } diff --git a/drivers/pikpak/types.go b/drivers/pikpak/types.go index a831642e27f..b27b905568a 100644 --- a/drivers/pikpak/types.go +++ b/drivers/pikpak/types.go @@ -10,11 +10,6 @@ import ( 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 { Files []File `json:"files"` NextPageToken string `json:"next_page_token"` @@ -174,7 +169,6 @@ type ErrResp struct { ErrorCode int64 `json:"error_code"` ErrorMsg string `json:"error"` ErrorDescription string `json:"error_description"` - // ErrorDetails interface{} `json:"error_details"` } func (e *ErrResp) IsError() bool { @@ -199,37 +193,3 @@ type CaptchaTokenResponse struct { ExpiresIn int64 `json:"expires_in"` 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"` -} diff --git a/drivers/pikpak/util.go b/drivers/pikpak/util.go index a794001a3b3..d4cf64f05a1 100644 --- a/drivers/pikpak/util.go +++ b/drivers/pikpak/util.go @@ -4,7 +4,6 @@ import ( "crypto/md5" "crypto/sha1" "encoding/hex" - "errors" "fmt" "github.com/alist-org/alist/v3/pkg/utils" "net/http" @@ -53,15 +52,15 @@ func (d *PikPak) request(url string, method string, callback base.ReqCallback, r if resp != nil { req.SetResult(resp) } - var e RespErr + var e ErrResp req.SetError(&e) res, err := req.Execute(method, url) if err != nil { return nil, err } - if e.ErrorCode != 0 { - return nil, errors.New(e.Error) + if e.IsError() { + return nil, &e } return res.Body(), nil } @@ -101,7 +100,7 @@ func (d *PikPak) requestWithCaptchaToken(url string, method string, callback bas default: 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) { @@ -264,7 +263,7 @@ func (c *Common) GetCaptchaSign() (timestamp, sign string) { return } -// 刷新验证码token +// refreshCaptchaToken 刷新CaptchaToken func (d *PikPak) refreshCaptchaToken(action string, metas map[string]string) error { param := CaptchaTokenRequest{ Action: action,