mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
style: format quotaCardService.js with prettier
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,11 +26,13 @@ class QuotaCardService {
|
|||||||
}
|
}
|
||||||
// 没有 Redis 配置时,使用 config.js 默认值
|
// 没有 Redis 配置时,使用 config.js 默认值
|
||||||
const config = require('../../config/config')
|
const config = require('../../config/config')
|
||||||
return config.quotaCardLimits || {
|
return (
|
||||||
|
config.quotaCardLimits || {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
maxExpiryDays: 90,
|
maxExpiryDays: 90,
|
||||||
maxTotalCostLimit: 1000
|
maxTotalCostLimit: 1000
|
||||||
}
|
}
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('❌ Failed to get limits config:', error)
|
logger.error('❌ Failed to get limits config:', error)
|
||||||
return { enabled: true, maxExpiryDays: 90, maxTotalCostLimit: 1000 }
|
return { enabled: true, maxExpiryDays: 90, maxTotalCostLimit: 1000 }
|
||||||
@@ -343,7 +345,9 @@ class QuotaCardService {
|
|||||||
const maxAllowed = limits.maxTotalCostLimit - beforeLimit
|
const maxAllowed = limits.maxTotalCostLimit - beforeLimit
|
||||||
if (amountToAdd > maxAllowed) {
|
if (amountToAdd > maxAllowed) {
|
||||||
amountToAdd = Math.max(0, maxAllowed)
|
amountToAdd = Math.max(0, maxAllowed)
|
||||||
warnings.push(`额度已达上限,本次仅增加 ${amountToAdd} CC(原卡面 ${card.quotaAmount} CC)`)
|
warnings.push(
|
||||||
|
`额度已达上限,本次仅增加 ${amountToAdd} CC(原卡面 ${card.quotaAmount} CC)`
|
||||||
|
)
|
||||||
logger.warn(`额度卡兑换超出上限,已截断:原 ${card.quotaAmount} -> 实际 ${amountToAdd}`)
|
logger.warn(`额度卡兑换超出上限,已截断:原 ${card.quotaAmount} -> 实际 ${amountToAdd}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -395,7 +399,10 @@ class QuotaCardService {
|
|||||||
await redis.client.hset(`apikey:${apiKeyId}`, 'expiresAt', maxExpiry.toISOString())
|
await redis.client.hset(`apikey:${apiKeyId}`, 'expiresAt', maxExpiry.toISOString())
|
||||||
afterExpiry = maxExpiry.toISOString()
|
afterExpiry = maxExpiry.toISOString()
|
||||||
// 计算实际增加的天数,截断时统一用天
|
// 计算实际增加的天数,截断时统一用天
|
||||||
const actualDays = Math.max(0, Math.ceil((maxExpiry - baseDate) / (1000 * 60 * 60 * 24)))
|
const actualDays = Math.max(
|
||||||
|
0,
|
||||||
|
Math.ceil((maxExpiry - baseDate) / (1000 * 60 * 60 * 24))
|
||||||
|
)
|
||||||
timeAdded = actualDays
|
timeAdded = actualDays
|
||||||
actualTimeUnit = 'days'
|
actualTimeUnit = 'days'
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user