From 90a889f0ebfe73e5705445058d013790410d9758 Mon Sep 17 00:00:00 2001 From: xiaoyaofenfen <1254525673@qq.com> Date: Wed, 7 Dec 2022 17:24:02 +0800 Subject: [PATCH] fix webdav token refresh erorr --- internal/command/utils.go | 29 ++++------------------------- internal/command/webdav.go | 2 +- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/internal/command/utils.go b/internal/command/utils.go index e558098..0781a36 100644 --- a/internal/command/utils.go +++ b/internal/command/utils.go @@ -122,6 +122,10 @@ func RefreshTokenInNeed(activeUser *config.PanUser) bool { activeUser.PanClient().UpdateToken(*wt) logger.Verboseln("get new access token success") return true + } else { + // token refresh error + // if token has expired, callback plugin api + // TODO: plugin api callback } } } @@ -129,31 +133,6 @@ func RefreshTokenInNeed(activeUser *config.PanUser) bool { return false } -// ReloadRefreshTokenInNeed 从配置文件加载最新token -func ReloadRefreshTokenInNeed(activeUser *config.PanUser) bool { - if activeUser == nil { - return false - } - - // refresh expired token - if activeUser.PanClient() != nil { - if len(activeUser.WebToken.RefreshToken) > 0 { - cz := time.FixedZone("CST", 8*3600) // 东8区 - expiredTime, _ := time.ParseInLocation("2006-01-02 15:04:05", activeUser.WebToken.ExpireTime, cz) - now := time.Now() - if (expiredTime.Unix() - now.Unix()) <= (10 * 60) { // 10min - // reload refresh token from config file - u := config.Config.ActiveUser() - activeUser.WebToken = u.WebToken - activeUser.PanClient().UpdateToken(u.WebToken) - logger.Verboseln("reload access token from config file") - return true - } - } - } - return false -} - func isIncludeFile(pattern string, fileName string) bool { b, er := filepath.Match(pattern, fileName) if er != nil { diff --git a/internal/command/webdav.go b/internal/command/webdav.go index 9532a97..8cbf1da 100644 --- a/internal/command/webdav.go +++ b/internal/command/webdav.go @@ -77,7 +77,7 @@ aliyunpan webdav start -h // token刷新 time.Sleep(time.Duration(1) * time.Minute) //time.Sleep(time.Duration(5) * time.Second) - if ReloadRefreshTokenInNeed(activeUser) { + if RefreshTokenInNeed(activeUser) { logger.Verboseln("reload new access token for webdav") } }