fix login refresh token issue

This commit is contained in:
tickstep 2024-03-03 23:20:27 +08:00
parent 443eac7589
commit f531c7bc70
5 changed files with 23 additions and 9 deletions

View File

@ -304,7 +304,8 @@ func TryLogin() *config.PanUser {
config.Config.DeviceId, config.Config.DeviceName, config.Config.DeviceId, config.Config.DeviceName,
config.Config.ClientId, config.Config.ClientSecret) config.Config.ClientId, config.Config.ClientSecret)
if cloudUser == nil { if cloudUser == nil {
fmt.Println("尝试登录失败: ", err) logger.Verboseln("尝试登录失败: ", err)
fmt.Println("尝试登录失败,请使用 login 命令进行重新登录")
return nil return nil
} }

View File

@ -29,8 +29,3 @@ func (p *PanClient) WebapiPanClient() *aliyunpan_web.WebPanClient {
func (p *PanClient) OpenapiPanClient() *aliyunpan_open.OpenPanClient { func (p *PanClient) OpenapiPanClient() *aliyunpan_open.OpenPanClient {
return p.openapiPanClient return p.openapiPanClient
} }
func (p *PanClient) UpdateClient(openClient *aliyunpan_open.OpenPanClient, webClient *aliyunpan_web.WebPanClient) {
p.webapiPanClient = webClient
p.openapiPanClient = openClient
}

View File

@ -441,7 +441,7 @@ func (c *PanConfig) ActiveUser() *PanUser {
return u return u
} }
} }
return &PanUser{} return nil
} }
return c.activeUser return c.activeUser
} }
@ -455,7 +455,7 @@ func (c *PanConfig) SetActiveUser(user *PanUser) *PanUser {
u.WebapiToken = user.WebapiToken u.WebapiToken = user.WebapiToken
u.OpenapiToken = user.OpenapiToken u.OpenapiToken = user.OpenapiToken
u.TicketId = user.TicketId u.TicketId = user.TicketId
u.PanClient().UpdateClient(user.PanClient().OpenapiPanClient(), user.PanClient().WebapiPanClient()) u.UpdateClient(user.PanClient().OpenapiPanClient(), user.PanClient().WebapiPanClient())
needToInsert = false needToInsert = false
break break
} }

View File

@ -280,6 +280,18 @@ func (pu *PanUser) PanClient() *PanClient {
return pu.panClient return pu.panClient
} }
func (pu *PanUser) UpdateClient(openClient *aliyunpan_open.OpenPanClient, webClient *aliyunpan_web.WebPanClient) {
if pu.panClient == nil {
pu.panClient = &PanClient{
webapiPanClient: webClient,
openapiPanClient: openClient,
}
} else {
pu.panClient.webapiPanClient = webClient
pu.panClient.openapiPanClient = openClient
}
}
// PathJoin 合并工作目录和相对路径p, 若p为绝对路径则忽略 // PathJoin 合并工作目录和相对路径p, 若p为绝对路径则忽略
func (pu *PanUser) PathJoin(driveId, p string) string { func (pu *PanUser) PathJoin(driveId, p string) string {
if path.IsAbs(p) { if path.IsAbs(p) {

View File

@ -102,7 +102,13 @@ func main() {
// Token刷新进程不管是CLI命令行模式还是直接命令模式本刷新任务都会执行 // Token刷新进程不管是CLI命令行模式还是直接命令模式本刷新任务都会执行
time.Sleep(time.Duration(1) * time.Minute) time.Sleep(time.Duration(1) * time.Minute)
//time.Sleep(time.Duration(5) * time.Second) //time.Sleep(time.Duration(5) * time.Second)
checkLoginExpiredAndRelogin() for _, u := range config.Config.UserList {
if u.UserId == config.Config.ActiveUID {
if u.PanClient() != nil {
checkLoginExpiredAndRelogin()
}
}
}
} }
}() }()