mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
add relogin action when token expired
This commit is contained in:
parent
ea82ec8320
commit
b6b71b45e3
@ -6,6 +6,7 @@ import (
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
||||
"github.com/tickstep/aliyunpan/cmder/cmdliner"
|
||||
"github.com/tickstep/aliyunpan/internal/config"
|
||||
"github.com/tickstep/aliyunpan/internal/functions/panlogin"
|
||||
"github.com/tickstep/library-go/logger"
|
||||
"github.com/urfave/cli"
|
||||
"sync"
|
||||
@ -75,7 +76,29 @@ func TryLogin() *config.PanUser {
|
||||
// login
|
||||
_, webToken, err := DoLoginHelper(u.RefreshToken)
|
||||
if err != nil {
|
||||
logger.Verboseln("automatically login error")
|
||||
logger.Verboseln("automatically login use saved refresh token error ", err)
|
||||
if u.TokenId != "" {
|
||||
logger.Verboseln("try to login use tokenId")
|
||||
h := panlogin.NewLoginHelper(config.DefaultTokenServiceWebHost)
|
||||
r, e := h.GetRefreshToken(u.TokenId)
|
||||
if e != nil {
|
||||
logger.Verboseln("try to login use tokenId error", e)
|
||||
break
|
||||
}
|
||||
refreshToken, e := h.ParseSecureRefreshToken("", r.SecureRefreshToken)
|
||||
if e != nil {
|
||||
logger.Verboseln("try to parse refresh token error", e)
|
||||
break
|
||||
}
|
||||
_, webToken, err = DoLoginHelper(refreshToken)
|
||||
if err != nil {
|
||||
logger.Verboseln("try to use refresh token from tokenId error", e)
|
||||
break
|
||||
}
|
||||
fmt.Println("Token重新自动登录成功")
|
||||
// save new refresh token
|
||||
u.RefreshToken = refreshToken
|
||||
}
|
||||
break
|
||||
}
|
||||
// success
|
||||
@ -89,4 +112,4 @@ func TryLogin() *config.PanUser {
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func CmdLogout() cli.Command {
|
||||
|
||||
func RunLogin(useQrCodeLogin bool, refreshToken string) (tokenId, refreshTokenStr string, webToken aliyunpan.WebLoginToken, error error) {
|
||||
if useQrCodeLogin {
|
||||
h := panlogin.NewLoginHelper("http://localhost:8977")
|
||||
h := panlogin.NewLoginHelper(config.DefaultTokenServiceWebHost)
|
||||
qrCodeUrlResult, err := h.GetQRCodeLoginUrl("")
|
||||
if err != nil {
|
||||
fmt.Println("二维码登录错误:", err)
|
||||
|
@ -39,11 +39,15 @@ const (
|
||||
// ConfigVersion 配置文件版本
|
||||
ConfigVersion string = "1.0"
|
||||
|
||||
// DefaultUploadParallelNum 默认的文件上传并发数量
|
||||
// DefaultFileUploadParallelNum 默认的文件上传并发数量
|
||||
DefaultFileUploadParallelNum = 10
|
||||
|
||||
// DefaultFileDownloadParallelNum 默认的文件下载并发数量
|
||||
DefaultFileDownloadParallelNum = 5
|
||||
|
||||
// DefaultTokenServiceWebHost 默认的token服务
|
||||
DefaultTokenServiceWebHost = "http://api.tickstep.com"
|
||||
//DefaultTokenServiceWebHost = "http://localhost:8977"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -75,7 +79,7 @@ type PanConfig struct {
|
||||
|
||||
MaxDownloadRate int64 `json:"maxDownloadRate"` // 限制最大下载速度,单位 B/s, 即字节/每秒
|
||||
MaxUploadRate int64 `json:"maxUploadRate"` // 限制最大上传速度,单位 B/s, 即字节/每秒
|
||||
TransferUrlType int `json:"transferUrlType"` // 上传/下载URL类别,1-默认,2-阿里云ECS
|
||||
TransferUrlType int `json:"transferUrlType"` // 上传/下载URL类别,1-默认,2-阿里云ECS
|
||||
|
||||
SaveDir string `json:"saveDir"` // 下载储存路径
|
||||
|
||||
@ -282,7 +286,7 @@ func GetConfigDir() string {
|
||||
|
||||
// 3. ~/.aliyunpan/
|
||||
if runtime.GOOS == "linux" || runtime.GOOS == "windows" {
|
||||
cd,er := homedir.Expand("~/.aliyunpan")
|
||||
cd, er := homedir.Expand("~/.aliyunpan")
|
||||
if er == nil {
|
||||
if IsFolderExist(cd) {
|
||||
logger.Verboseln("use config dir: ", cd)
|
||||
@ -417,4 +421,4 @@ func (c *PanConfig) HTTPClient(ua string) *requester.HTTPClient {
|
||||
client.SetUserAgent(ua)
|
||||
}
|
||||
return client
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,6 @@ type QRCodeLoginResult struct {
|
||||
}
|
||||
|
||||
func NewLoginHelper(webHost string) *LoginHelper {
|
||||
if webHost == "" {
|
||||
webHost = "http://api.tickstep.com"
|
||||
}
|
||||
return &LoginHelper{
|
||||
webHost: webHost,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user