From af4813db30f3aa1f77b78a0d711e4f7d74797b5b Mon Sep 17 00:00:00 2001 From: k3-cat Date: Fri, 4 Jul 2025 16:27:47 +1000 Subject: [PATCH] feat: better autorenewal (#305) --- service/user.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/service/user.go b/service/user.go index 972be89..c509b98 100644 --- a/service/user.go +++ b/service/user.go @@ -2,14 +2,14 @@ package service import ( "errors" - "github.com/lejianwen/rustdesk-api/v2/model" - "github.com/lejianwen/rustdesk-api/v2/utils" "math/rand" "strconv" "strings" "time" "github.com/gin-gonic/gin" + "github.com/lejianwen/rustdesk-api/v2/model" + "github.com/lejianwen/rustdesk-api/v2/utils" "gorm.io/gorm" ) @@ -500,8 +500,9 @@ func (us *UserService) RefreshAccessToken(ut *model.UserToken) { ut.ExpiredAt = us.UserTokenExpireTimestamp() DB.Model(ut).Update("expired_at", ut.ExpiredAt) } + func (us *UserService) AutoRefreshAccessToken(ut *model.UserToken) { - if ut.ExpiredAt-time.Now().Unix() < 86400 { + if ut.ExpiredAt-time.Now().Unix() < Config.App.TokenExpire.Milliseconds()/3000 { us.RefreshAccessToken(ut) } }