From c3dadd00b7749868d82b3c69fd3fb580b44a7e35 Mon Sep 17 00:00:00 2001 From: xiaoyaofenfen <1254525673@qq.com> Date: Wed, 7 Dec 2022 17:35:03 +0800 Subject: [PATCH] add token plugin callback for token refresh routine --- internal/command/utils.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/command/utils.go b/internal/command/utils.go index 0781a36..58d78df 100644 --- a/internal/command/utils.go +++ b/internal/command/utils.go @@ -17,6 +17,8 @@ import ( "fmt" "github.com/tickstep/aliyunpan-api/aliyunpan" "github.com/tickstep/aliyunpan/internal/config" + "github.com/tickstep/aliyunpan/internal/plugins" + "github.com/tickstep/aliyunpan/internal/utils" "github.com/tickstep/library-go/logger" "math/rand" "net/url" @@ -124,8 +126,21 @@ func RefreshTokenInNeed(activeUser *config.PanUser) bool { return true } else { // token refresh error - // if token has expired, callback plugin api - // TODO: plugin api callback + // if token has expired, callback plugin api for notify + if now.Unix() >= expiredTime.Unix() { + pluginManger := plugins.NewPluginManager(config.GetPluginDir()) + plugin, _ := pluginManger.GetPlugin() + params := &plugins.UserTokenRefreshFinishParams{ + Result: "fail", + Message: er.Error(), + OldToken: activeUser.RefreshToken, + NewToken: "", + UpdatedAt: utils.NowTimeStr(), + } + if er1 := plugin.UserTokenRefreshFinishCallback(plugins.GetContext(activeUser), params); er1 != nil { + logger.Verbosef("UserTokenRefreshFinishCallback error: " + er1.Error()) + } + } } } }