diff --git a/internal/command/utils.go b/internal/command/utils.go index 249c44b..e5d09fd 100644 --- a/internal/command/utils.go +++ b/internal/command/utils.go @@ -304,7 +304,8 @@ func TryLogin() *config.PanUser { config.Config.DeviceId, config.Config.DeviceName, config.Config.ClientId, config.Config.ClientSecret) if cloudUser == nil { - fmt.Println("尝试登录失败: ", err) + logger.Verboseln("尝试登录失败: ", err) + fmt.Println("尝试登录失败,请使用 login 命令进行重新登录") return nil } diff --git a/internal/config/pan_client.go b/internal/config/pan_client.go index e89982e..8d56cd2 100644 --- a/internal/config/pan_client.go +++ b/internal/config/pan_client.go @@ -29,8 +29,3 @@ func (p *PanClient) WebapiPanClient() *aliyunpan_web.WebPanClient { func (p *PanClient) OpenapiPanClient() *aliyunpan_open.OpenPanClient { return p.openapiPanClient } - -func (p *PanClient) UpdateClient(openClient *aliyunpan_open.OpenPanClient, webClient *aliyunpan_web.WebPanClient) { - p.webapiPanClient = webClient - p.openapiPanClient = openClient -} diff --git a/internal/config/pan_config.go b/internal/config/pan_config.go index a8fedac..0a9f054 100644 --- a/internal/config/pan_config.go +++ b/internal/config/pan_config.go @@ -441,7 +441,7 @@ func (c *PanConfig) ActiveUser() *PanUser { return u } } - return &PanUser{} + return nil } return c.activeUser } @@ -455,7 +455,7 @@ func (c *PanConfig) SetActiveUser(user *PanUser) *PanUser { u.WebapiToken = user.WebapiToken u.OpenapiToken = user.OpenapiToken u.TicketId = user.TicketId - u.PanClient().UpdateClient(user.PanClient().OpenapiPanClient(), user.PanClient().WebapiPanClient()) + u.UpdateClient(user.PanClient().OpenapiPanClient(), user.PanClient().WebapiPanClient()) needToInsert = false break } diff --git a/internal/config/pan_user.go b/internal/config/pan_user.go index 08d8ef8..e718fff 100644 --- a/internal/config/pan_user.go +++ b/internal/config/pan_user.go @@ -280,6 +280,18 @@ func (pu *PanUser) PanClient() *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为绝对路径则忽略 func (pu *PanUser) PathJoin(driveId, p string) string { if path.IsAbs(p) { diff --git a/main.go b/main.go index 1d97062..ae8f453 100644 --- a/main.go +++ b/main.go @@ -102,7 +102,13 @@ func main() { // Token刷新进程,不管是CLI命令行模式,还是直接命令模式,本刷新任务都会执行 time.Sleep(time.Duration(1) * time.Minute) //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() + } + } + } } }()