mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 22:42:15 +08:00
fix webdav token refresh erorr
This commit is contained in:
parent
5935f78824
commit
90a889f0eb
@ -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 {
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user