mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-17 01:06:37 +08:00
调整Google认证的Token过期时间,选择从Token认证请求中获取过期时间,如果不存在会选择默认时间
This commit is contained in:
parent
3e9f5ad0c7
commit
55155e0fb6
@ -57,6 +57,17 @@ func getToken(ctx context.Context, channelId int, adcJson string) (string, error
|
|||||||
}
|
}
|
||||||
_ = resp
|
_ = resp
|
||||||
|
|
||||||
Cache.Set(cacheKey, resp.AccessToken, cache.DefaultExpiration)
|
// 使用响应中的过期时间,如果获取失败则使用默认时间
|
||||||
|
expiration := cache.DefaultExpiration
|
||||||
|
if resp.ExpireTime != nil {
|
||||||
|
_expiration := time.Until(resp.ExpireTime.AsTime())
|
||||||
|
// 提前10分钟过期,避免边界情况
|
||||||
|
_expiration = _expiration - 10*time.Minute
|
||||||
|
if _expiration > 0 {
|
||||||
|
expiration = _expiration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache.Set(cacheKey, resp.AccessToken, expiration)
|
||||||
return resp.AccessToken, nil
|
return resp.AccessToken, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user