mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
refactor: improve readability of conditional statements
This commit is contained in:
@@ -827,15 +827,21 @@ class UnifiedClaudeScheduler {
|
|||||||
const remainingTTL = await client.ttl(key)
|
const remainingTTL = await client.ttl(key)
|
||||||
|
|
||||||
// -2: key 不存在;-1: 无过期时间
|
// -2: key 不存在;-1: 无过期时间
|
||||||
if (remainingTTL === -2) return false
|
if (remainingTTL === -2) {
|
||||||
if (remainingTTL === -1) return true
|
return false
|
||||||
|
}
|
||||||
|
if (remainingTTL === -1) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const appConfig = require('../../config/config')
|
const appConfig = require('../../config/config')
|
||||||
const ttlHours = appConfig.session?.stickyTtlHours || 1
|
const ttlHours = appConfig.session?.stickyTtlHours || 1
|
||||||
const renewalThresholdMinutes = appConfig.session?.renewalThresholdMinutes || 0
|
const renewalThresholdMinutes = appConfig.session?.renewalThresholdMinutes || 0
|
||||||
|
|
||||||
// 阈值为0则不续期
|
// 阈值为0则不续期
|
||||||
if (!renewalThresholdMinutes) return true
|
if (!renewalThresholdMinutes) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const fullTTL = Math.max(1, Math.floor(ttlHours * 60 * 60))
|
const fullTTL = Math.max(1, Math.floor(ttlHours * 60 * 60))
|
||||||
const threshold = Math.max(0, Math.floor(renewalThresholdMinutes * 60))
|
const threshold = Math.max(0, Math.floor(renewalThresholdMinutes * 60))
|
||||||
|
|||||||
@@ -305,13 +305,19 @@ class UnifiedGeminiScheduler {
|
|||||||
const key = `${this.SESSION_MAPPING_PREFIX}${sessionHash}`
|
const key = `${this.SESSION_MAPPING_PREFIX}${sessionHash}`
|
||||||
const remainingTTL = await client.ttl(key)
|
const remainingTTL = await client.ttl(key)
|
||||||
|
|
||||||
if (remainingTTL === -2) return false
|
if (remainingTTL === -2) {
|
||||||
if (remainingTTL === -1) return true
|
return false
|
||||||
|
}
|
||||||
|
if (remainingTTL === -1) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const appConfig = require('../../config/config')
|
const appConfig = require('../../config/config')
|
||||||
const ttlHours = appConfig.session?.stickyTtlHours || 1
|
const ttlHours = appConfig.session?.stickyTtlHours || 1
|
||||||
const renewalThresholdMinutes = appConfig.session?.renewalThresholdMinutes || 0
|
const renewalThresholdMinutes = appConfig.session?.renewalThresholdMinutes || 0
|
||||||
if (!renewalThresholdMinutes) return true
|
if (!renewalThresholdMinutes) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const fullTTL = Math.max(1, Math.floor(ttlHours * 60 * 60))
|
const fullTTL = Math.max(1, Math.floor(ttlHours * 60 * 60))
|
||||||
const threshold = Math.max(0, Math.floor(renewalThresholdMinutes * 60))
|
const threshold = Math.max(0, Math.floor(renewalThresholdMinutes * 60))
|
||||||
|
|||||||
@@ -311,13 +311,19 @@ class UnifiedOpenAIScheduler {
|
|||||||
const key = `${this.SESSION_MAPPING_PREFIX}${sessionHash}`
|
const key = `${this.SESSION_MAPPING_PREFIX}${sessionHash}`
|
||||||
const remainingTTL = await client.ttl(key)
|
const remainingTTL = await client.ttl(key)
|
||||||
|
|
||||||
if (remainingTTL === -2) return false
|
if (remainingTTL === -2) {
|
||||||
if (remainingTTL === -1) return true
|
return false
|
||||||
|
}
|
||||||
|
if (remainingTTL === -1) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const appConfig = require('../../config/config')
|
const appConfig = require('../../config/config')
|
||||||
const ttlHours = appConfig.session?.stickyTtlHours || 1
|
const ttlHours = appConfig.session?.stickyTtlHours || 1
|
||||||
const renewalThresholdMinutes = appConfig.session?.renewalThresholdMinutes || 0
|
const renewalThresholdMinutes = appConfig.session?.renewalThresholdMinutes || 0
|
||||||
if (!renewalThresholdMinutes) return true
|
if (!renewalThresholdMinutes) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const fullTTL = Math.max(1, Math.floor(ttlHours * 60 * 60))
|
const fullTTL = Math.max(1, Math.floor(ttlHours * 60 * 60))
|
||||||
const threshold = Math.max(0, Math.floor(renewalThresholdMinutes * 60))
|
const threshold = Math.max(0, Math.floor(renewalThresholdMinutes * 60))
|
||||||
|
|||||||
Reference in New Issue
Block a user