feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
1 parent
aa6c3f50f4
commit
ceddfd3d6b
828 files changed
+122253
-13702
No files matched your search
+21
-6
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func getTokenCacheKey(key string) string {
|
||||
return fmt.Sprintf("token:%s", common.GenerateHMAC(key))
|
||||
return fmt.Sprintf("token:v2:%s", common.GenerateHMAC(key))
|
||||
}
|
||||
|
||||
func getTokenCacheFenceKey(key string) string {
|
||||
@@ -51,7 +51,7 @@ func invalidateTokenCacheForMutation(key string) error {
|
||||
// active and the hash is cold. An existing hash only gets its TTL refreshed:
|
||||
// its RemainQuota may already be ahead of this snapshot because atomic
|
||||
// pre-consume decrements Redis first, so a snapshot must never overwrite any
|
||||
// field of a live hash.
|
||||
// quota field of a live hash. Only missing policy metadata is hydrated.
|
||||
// 返回值:0=被 fence 拦截,1=完成初始化,2=哈希已存在,仅刷新 TTL。
|
||||
func cacheInitToken(token Token) (int, error) {
|
||||
if !common.RedisEnabled {
|
||||
@@ -66,7 +66,9 @@ if redis.call('EXISTS', KEYS[2]) == 1 then
|
||||
return 0
|
||||
end
|
||||
if redis.call('EXISTS', KEYS[1]) == 1 then
|
||||
redis.call('EXPIRE', KEYS[1], ARGV[17])
|
||||
redis.call('HSETNX', KEYS[1], 'AstraAutoSwitch', ARGV[14])
|
||||
redis.call('HSETNX', KEYS[1], 'AstraDetectionEnabled', ARGV[20])
|
||||
redis.call('EXPIRE', KEYS[1], ARGV[18])
|
||||
return 2
|
||||
end
|
||||
redis.call('HSET', KEYS[1],
|
||||
@@ -74,8 +76,8 @@ redis.call('HSET', KEYS[1],
|
||||
'CreatedTime', ARGV[5], 'AccessedTime', ARGV[6], 'ExpiredTime', ARGV[7],
|
||||
'UnlimitedQuota', ARGV[8], 'ModelLimitsEnabled', ARGV[9], 'ModelLimits', ARGV[10],
|
||||
'AllowIps', ARGV[11], 'Group', ARGV[12], 'CrossGroupRetry', ARGV[13],
|
||||
'AutoGroups', ARGV[14], 'RemainQuota', ARGV[15], 'UsedQuota', ARGV[16])
|
||||
redis.call('EXPIRE', KEYS[1], ARGV[17])
|
||||
'AstraAutoSwitch', ARGV[14], 'AutoGroups', ARGV[15], 'RemainQuota', ARGV[16], 'UsedQuota', ARGV[17], 'RoutingPolicy', ARGV[19], 'AstraDetectionEnabled', ARGV[20])
|
||||
redis.call('EXPIRE', KEYS[1], ARGV[18])
|
||||
return 1`
|
||||
|
||||
return common.RDB.Eval(context.Background(), script, []string{
|
||||
@@ -85,8 +87,9 @@ return 1`
|
||||
token.CreatedTime, token.AccessedTime, token.ExpiredTime,
|
||||
strconv.FormatBool(token.UnlimitedQuota), strconv.FormatBool(token.ModelLimitsEnabled),
|
||||
token.ModelLimits, allowIps, token.Group, strconv.FormatBool(token.CrossGroupRetry),
|
||||
token.AutoGroups, token.RemainQuota, token.UsedQuota,
|
||||
strconv.FormatBool(token.AstraAutoSwitch), token.AutoGroups, token.RemainQuota, token.UsedQuota,
|
||||
tokenCacheTTLSeconds(),
|
||||
token.RoutingPolicy, strconv.FormatBool(token.AstraDetectionEnabled),
|
||||
).Int()
|
||||
}
|
||||
|
||||
@@ -95,6 +98,18 @@ func cacheGetTokenByKey(key string) (*Token, error) {
|
||||
if !common.RedisEnabled {
|
||||
return nil, fmt.Errorf("redis is not enabled")
|
||||
}
|
||||
// A pre-migration cache hash does not contain the policy field. Force a DB
|
||||
// refresh so legacy tokens retain their migrated default instead of being
|
||||
// interpreted as false until the old cache expires.
|
||||
if exists, err := common.RDB.HExists(context.Background(), getTokenCacheKey(key), "AstraAutoSwitch").Result(); err != nil || !exists {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("token cache is missing AstraAutoSwitch")
|
||||
}
|
||||
if exists, err := common.RDB.HExists(context.Background(), getTokenCacheKey(key), "AstraDetectionEnabled").Result(); err != nil || !exists {
|
||||
return nil, fmt.Errorf("token cache is missing AstraDetectionEnabled")
|
||||
}
|
||||
var token Token
|
||||
if err := common.RedisHGetObj(getTokenCacheKey(key), &token); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in new issue
Block a user