mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
chore: fix prettier formatting
This commit is contained in:
@@ -20,7 +20,9 @@ function getDateInTimezone(date = new Date()) {
|
||||
function getDateStringInTimezone(date = new Date()) {
|
||||
const tzDate = getDateInTimezone(date)
|
||||
// 使用UTC方法获取偏移后的日期部分
|
||||
return `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}-${String(tzDate.getUTCDate()).padStart(2, '0')}`
|
||||
return `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}-${String(
|
||||
tzDate.getUTCDate()
|
||||
).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
// 获取配置时区的小时 (0-23)
|
||||
@@ -219,7 +221,10 @@ class RedisClient {
|
||||
const now = new Date()
|
||||
const today = getDateStringInTimezone(now)
|
||||
const tzDate = getDateInTimezone(now)
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}`
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(
|
||||
2,
|
||||
'0'
|
||||
)}`
|
||||
const currentHour = `${today}:${String(getHourInTimezone(now)).padStart(2, '0')}` // 新增小时级别
|
||||
|
||||
const daily = `usage:daily:${keyId}:${today}`
|
||||
@@ -414,7 +419,10 @@ class RedisClient {
|
||||
const now = new Date()
|
||||
const today = getDateStringInTimezone(now)
|
||||
const tzDate = getDateInTimezone(now)
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}`
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(
|
||||
2,
|
||||
'0'
|
||||
)}`
|
||||
const currentHour = `${today}:${String(getHourInTimezone(now)).padStart(2, '0')}`
|
||||
|
||||
// 账户级别统计的键
|
||||
@@ -551,7 +559,10 @@ class RedisClient {
|
||||
const today = getDateStringInTimezone()
|
||||
const dailyKey = `usage:daily:${keyId}:${today}`
|
||||
const tzDate = getDateInTimezone()
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}`
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(
|
||||
2,
|
||||
'0'
|
||||
)}`
|
||||
const monthlyKey = `usage:monthly:${keyId}:${currentMonth}`
|
||||
|
||||
const [total, daily, monthly] = await Promise.all([
|
||||
@@ -694,7 +705,10 @@ class RedisClient {
|
||||
async incrementDailyCost(keyId, amount) {
|
||||
const today = getDateStringInTimezone()
|
||||
const tzDate = getDateInTimezone()
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}`
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(
|
||||
2,
|
||||
'0'
|
||||
)}`
|
||||
const currentHour = `${today}:${String(getHourInTimezone(new Date())).padStart(2, '0')}`
|
||||
|
||||
const dailyKey = `usage:cost:daily:${keyId}:${today}`
|
||||
@@ -724,7 +738,10 @@ class RedisClient {
|
||||
async getCostStats(keyId) {
|
||||
const today = getDateStringInTimezone()
|
||||
const tzDate = getDateInTimezone()
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}`
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(
|
||||
2,
|
||||
'0'
|
||||
)}`
|
||||
const currentHour = `${today}:${String(getHourInTimezone(new Date())).padStart(2, '0')}`
|
||||
|
||||
const [daily, monthly, hourly, total] = await Promise.all([
|
||||
@@ -827,7 +844,10 @@ class RedisClient {
|
||||
const today = getDateStringInTimezone()
|
||||
const accountDailyKey = `account_usage:daily:${accountId}:${today}`
|
||||
const tzDate = getDateInTimezone()
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(2, '0')}`
|
||||
const currentMonth = `${tzDate.getUTCFullYear()}-${String(tzDate.getUTCMonth() + 1).padStart(
|
||||
2,
|
||||
'0'
|
||||
)}`
|
||||
const accountMonthlyKey = `account_usage:monthly:${accountId}:${currentMonth}`
|
||||
|
||||
const [total, daily, monthly] = await Promise.all([
|
||||
@@ -1463,14 +1483,18 @@ class RedisClient {
|
||||
if (remainingTTL < renewalThreshold) {
|
||||
await this.client.expire(key, fullTTL)
|
||||
logger.debug(
|
||||
`🔄 Renewed sticky session TTL: ${sessionHash} (was ${Math.round(remainingTTL / 60)}min, renewed to ${ttlHours}h)`
|
||||
`🔄 Renewed sticky session TTL: ${sessionHash} (was ${Math.round(
|
||||
remainingTTL / 60
|
||||
)}min, renewed to ${ttlHours}h)`
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
// 剩余时间充足,无需续期
|
||||
logger.debug(
|
||||
`✅ Sticky session TTL sufficient: ${sessionHash} (remaining ${Math.round(remainingTTL / 60)}min)`
|
||||
`✅ Sticky session TTL sufficient: ${sessionHash} (remaining ${Math.round(
|
||||
remainingTTL / 60
|
||||
)}min)`
|
||||
)
|
||||
return true
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user