mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
fix: 修复PR #458中的totalCostLimit功能问题
主要修复: - 移除重复的totalUsageLimit字段,统一使用totalCostLimit - 删除auth.js中重复的总费用限制检查逻辑 - 删除admin.js中重复的totalCostLimit验证代码 - 更新所有前端组件,移除totalUsageLimit引用 功能改进: - 确保totalCostLimit作为永久累计费用限制正常工作 - 与dailyCostLimit(每日重置)功能互补 - 适用于预付费、一次性API Key场景 测试: - 删除有逻辑错误的test-total-usage-limit.js - 创建新的test-total-cost-limit.js验证功能正确性 - 所有测试通过,功能正常工作 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -550,7 +550,6 @@ router.post('/api-keys', authenticateAdmin, async (req, res) => {
|
||||
enableClientRestriction,
|
||||
allowedClients,
|
||||
dailyCostLimit,
|
||||
totalUsageLimit,
|
||||
totalCostLimit,
|
||||
weeklyOpusCostLimit,
|
||||
tags,
|
||||
@@ -634,22 +633,6 @@ router.post('/api-keys', authenticateAdmin, async (req, res) => {
|
||||
return res.status(400).json({ error: 'All tags must be non-empty strings' })
|
||||
}
|
||||
|
||||
if (totalUsageLimit !== undefined && totalUsageLimit !== null && totalUsageLimit !== '') {
|
||||
const usageLimit = Number(totalUsageLimit)
|
||||
if (Number.isNaN(usageLimit) || usageLimit < 0) {
|
||||
return res.status(400).json({ error: 'Total usage limit must be a non-negative number' })
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
totalCostLimit !== undefined &&
|
||||
totalCostLimit !== null &&
|
||||
totalCostLimit !== '' &&
|
||||
(Number.isNaN(Number(totalCostLimit)) || Number(totalCostLimit) < 0)
|
||||
) {
|
||||
return res.status(400).json({ error: 'Total cost limit must be a non-negative number' })
|
||||
}
|
||||
|
||||
if (
|
||||
totalCostLimit !== undefined &&
|
||||
totalCostLimit !== null &&
|
||||
@@ -704,7 +687,6 @@ router.post('/api-keys', authenticateAdmin, async (req, res) => {
|
||||
enableClientRestriction,
|
||||
allowedClients,
|
||||
dailyCostLimit,
|
||||
totalUsageLimit,
|
||||
totalCostLimit,
|
||||
weeklyOpusCostLimit,
|
||||
tags,
|
||||
@@ -745,7 +727,6 @@ router.post('/api-keys/batch', authenticateAdmin, async (req, res) => {
|
||||
enableClientRestriction,
|
||||
allowedClients,
|
||||
dailyCostLimit,
|
||||
totalUsageLimit,
|
||||
totalCostLimit,
|
||||
weeklyOpusCostLimit,
|
||||
tags,
|
||||
@@ -796,7 +777,6 @@ router.post('/api-keys/batch', authenticateAdmin, async (req, res) => {
|
||||
enableClientRestriction,
|
||||
allowedClients,
|
||||
dailyCostLimit,
|
||||
totalUsageLimit,
|
||||
totalCostLimit,
|
||||
weeklyOpusCostLimit,
|
||||
tags,
|
||||
@@ -915,9 +895,6 @@ router.put('/api-keys/batch', authenticateAdmin, async (req, res) => {
|
||||
if (updates.dailyCostLimit !== undefined) {
|
||||
finalUpdates.dailyCostLimit = updates.dailyCostLimit
|
||||
}
|
||||
if (updates.totalUsageLimit !== undefined) {
|
||||
finalUpdates.totalUsageLimit = updates.totalUsageLimit
|
||||
}
|
||||
if (updates.totalCostLimit !== undefined) {
|
||||
finalUpdates.totalCostLimit = updates.totalCostLimit
|
||||
}
|
||||
@@ -1049,7 +1026,6 @@ router.put('/api-keys/:keyId', authenticateAdmin, async (req, res) => {
|
||||
allowedClients,
|
||||
expiresAt,
|
||||
dailyCostLimit,
|
||||
totalUsageLimit,
|
||||
totalCostLimit,
|
||||
weeklyOpusCostLimit,
|
||||
tags,
|
||||
@@ -1208,14 +1184,6 @@ router.put('/api-keys/:keyId', authenticateAdmin, async (req, res) => {
|
||||
updates.totalCostLimit = costLimit
|
||||
}
|
||||
|
||||
if (totalUsageLimit !== undefined && totalUsageLimit !== null && totalUsageLimit !== '') {
|
||||
const usageLimit = Number(totalUsageLimit)
|
||||
if (Number.isNaN(usageLimit) || usageLimit < 0) {
|
||||
return res.status(400).json({ error: 'Total usage limit must be a non-negative number' })
|
||||
}
|
||||
updates.totalUsageLimit = usageLimit
|
||||
}
|
||||
|
||||
// 处理 Opus 周费用限制
|
||||
if (
|
||||
weeklyOpusCostLimit !== undefined &&
|
||||
|
||||
Reference in New Issue
Block a user