mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
fix: resolve all ESLint errors
- droidRelayService: add missing keyId variable declaration - quotaCardService: use object destructuring for actualDeducted - apiKeyService: remove unused variables and duplicate requires - redis: remove shadowed logger/config requires - unifiedGeminiScheduler: rename isActive param to avoid shadow - commonHelper: add comments to empty catch blocks - testPayloadHelper: prefix unused model param with underscore Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4916,7 +4916,6 @@ redisClient.removeFromIndex = async function (indexKey, id) {
|
|||||||
|
|
||||||
// 迁移全局统计数据(从 API Key 数据聚合)
|
// 迁移全局统计数据(从 API Key 数据聚合)
|
||||||
redisClient.migrateGlobalStats = async function () {
|
redisClient.migrateGlobalStats = async function () {
|
||||||
const logger = require('../utils/logger')
|
|
||||||
logger.info('🔄 开始迁移全局统计数据...')
|
logger.info('🔄 开始迁移全局统计数据...')
|
||||||
|
|
||||||
const keyIds = await this.scanApiKeyIds()
|
const keyIds = await this.scanApiKeyIds()
|
||||||
@@ -4978,8 +4977,6 @@ redisClient.migrateGlobalStats = async function () {
|
|||||||
|
|
||||||
// 确保月份索引完整(后台检查,补充缺失的月份)
|
// 确保月份索引完整(后台检查,补充缺失的月份)
|
||||||
redisClient.ensureMonthlyMonthsIndex = async function () {
|
redisClient.ensureMonthlyMonthsIndex = async function () {
|
||||||
const logger = require('../utils/logger')
|
|
||||||
|
|
||||||
// 扫描所有月份 key
|
// 扫描所有月份 key
|
||||||
const monthlyKeys = await this.client.keys('usage:model:monthly:*')
|
const monthlyKeys = await this.client.keys('usage:model:monthly:*')
|
||||||
const allMonths = new Set()
|
const allMonths = new Set()
|
||||||
@@ -5064,7 +5061,6 @@ redisClient.getApiKeyCount = async function () {
|
|||||||
|
|
||||||
// 清理过期的系统分钟统计数据(启动时调用)
|
// 清理过期的系统分钟统计数据(启动时调用)
|
||||||
redisClient.cleanupSystemMetrics = async function () {
|
redisClient.cleanupSystemMetrics = async function () {
|
||||||
const logger = require('../utils/logger')
|
|
||||||
logger.info('🧹 清理过期的系统分钟统计数据...')
|
logger.info('🧹 清理过期的系统分钟统计数据...')
|
||||||
|
|
||||||
const keys = await this.scanKeys('system:metrics:minute:*')
|
const keys = await this.scanKeys('system:metrics:minute:*')
|
||||||
@@ -5074,7 +5070,6 @@ redisClient.cleanupSystemMetrics = async function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 计算当前分钟时间戳和保留窗口
|
// 计算当前分钟时间戳和保留窗口
|
||||||
const config = require('../../config/config')
|
|
||||||
const metricsWindow = config.system?.metricsWindow || 5
|
const metricsWindow = config.system?.metricsWindow || 5
|
||||||
const currentMinute = Math.floor(Date.now() / 60000)
|
const currentMinute = Math.floor(Date.now() / 60000)
|
||||||
const keepAfter = currentMinute - metricsWindow * 2 // 保留窗口的2倍
|
const keepAfter = currentMinute - metricsWindow * 2 // 保留窗口的2倍
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class ApiKeyService {
|
|||||||
const hashedKey = this._hashApiKey(apiKey)
|
const hashedKey = this._hashApiKey(apiKey)
|
||||||
|
|
||||||
// 处理 permissions
|
// 处理 permissions
|
||||||
const permissionsValue = permissions
|
const _permissionsValue = permissions
|
||||||
|
|
||||||
const keyData = {
|
const keyData = {
|
||||||
id: keyId,
|
id: keyId,
|
||||||
@@ -235,14 +235,6 @@ class ApiKeyService {
|
|||||||
|
|
||||||
logger.success(`🔑 Generated new API key: ${name} (${keyId})`)
|
logger.success(`🔑 Generated new API key: ${name} (${keyId})`)
|
||||||
|
|
||||||
// 解析 permissions 用于返回
|
|
||||||
let parsedPermissions = keyData.permissions
|
|
||||||
try {
|
|
||||||
parsedPermissions = JSON.parse(keyData.permissions)
|
|
||||||
} catch (e) {
|
|
||||||
// 不是 JSON,保持原值(传统 Key 的字符串格式)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: keyId,
|
id: keyId,
|
||||||
apiKey, // 只在创建时返回完整的key
|
apiKey, // 只在创建时返回完整的key
|
||||||
@@ -410,14 +402,6 @@ class ApiKeyService {
|
|||||||
tags = []
|
tags = []
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析 permissions(聚合 Key 为数组,传统 Key 为字符串)
|
|
||||||
let permissions = keyData.permissions || 'all'
|
|
||||||
try {
|
|
||||||
permissions = JSON.parse(keyData.permissions)
|
|
||||||
} catch (e) {
|
|
||||||
// 不是 JSON,保持原值
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析 serviceRates
|
// 解析 serviceRates
|
||||||
let serviceRates = {}
|
let serviceRates = {}
|
||||||
try {
|
try {
|
||||||
@@ -1549,7 +1533,6 @@ class ApiKeyService {
|
|||||||
const realCost = costInfo.costs.total
|
const realCost = costInfo.costs.total
|
||||||
let ratedCost = realCost
|
let ratedCost = realCost
|
||||||
if (realCost > 0) {
|
if (realCost > 0) {
|
||||||
const serviceRatesService = require('./serviceRatesService')
|
|
||||||
const service = serviceRatesService.getService(accountType, model)
|
const service = serviceRatesService.getService(accountType, model)
|
||||||
ratedCost = await this.calculateRatedCost(keyId, service, realCost)
|
ratedCost = await this.calculateRatedCost(keyId, service, realCost)
|
||||||
}
|
}
|
||||||
@@ -1761,7 +1744,6 @@ class ApiKeyService {
|
|||||||
const realCostWithDetails = costInfo.totalCost || 0
|
const realCostWithDetails = costInfo.totalCost || 0
|
||||||
let ratedCostWithDetails = realCostWithDetails
|
let ratedCostWithDetails = realCostWithDetails
|
||||||
if (realCostWithDetails > 0) {
|
if (realCostWithDetails > 0) {
|
||||||
const serviceRatesService = require('./serviceRatesService')
|
|
||||||
const service = serviceRatesService.getService(accountType, model)
|
const service = serviceRatesService.getService(accountType, model)
|
||||||
ratedCostWithDetails = await this.calculateRatedCost(keyId, service, realCostWithDetails)
|
ratedCostWithDetails = await this.calculateRatedCost(keyId, service, realCostWithDetails)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -405,6 +405,7 @@ class DroidRelayService {
|
|||||||
) {
|
) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const url = new URL(apiUrl)
|
const url = new URL(apiUrl)
|
||||||
|
const keyId = apiKeyData?.id
|
||||||
const bodyString = JSON.stringify(processedBody)
|
const bodyString = JSON.stringify(processedBody)
|
||||||
const contentLength = Buffer.byteLength(bodyString)
|
const contentLength = Buffer.byteLength(bodyString)
|
||||||
const requestHeaders = {
|
const requestHeaders = {
|
||||||
@@ -1198,6 +1199,7 @@ class DroidRelayService {
|
|||||||
skipUsageRecord = false
|
skipUsageRecord = false
|
||||||
) {
|
) {
|
||||||
const { data } = response
|
const { data } = response
|
||||||
|
const keyId = apiKeyData?.id
|
||||||
|
|
||||||
// 从响应中提取 usage 数据
|
// 从响应中提取 usage 数据
|
||||||
const usage = data.usage || {}
|
const usage = data.usage || {}
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ class QuotaCardService {
|
|||||||
redemptionData.apiKeyId,
|
redemptionData.apiKeyId,
|
||||||
parseFloat(redemptionData.quotaAdded)
|
parseFloat(redemptionData.quotaAdded)
|
||||||
)
|
)
|
||||||
actualDeducted = result.actualDeducted
|
;({ actualDeducted } = result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:时间卡撤销比较复杂,这里简化处理,不回退时间
|
// 注意:时间卡撤销比较复杂,这里简化处理,不回退时间
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ class UnifiedGeminiScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 🔧 辅助方法:检查账户是否激活(兼容字符串和布尔值)
|
// 🔧 辅助方法:检查账户是否激活(兼容字符串和布尔值)
|
||||||
_isActive(isActive) {
|
_isActive(activeValue) {
|
||||||
// 兼容布尔值 true 和字符串 'true'
|
// 兼容布尔值 true 和字符串 'true'
|
||||||
return isActive === true || isActive === 'true'
|
return activeValue === true || activeValue === 'true'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🎯 统一调度Gemini账号
|
// 🎯 统一调度Gemini账号
|
||||||
|
|||||||
@@ -333,10 +333,14 @@ const getAppVersion = () => {
|
|||||||
if (fs.existsSync(versionFile)) {
|
if (fs.existsSync(versionFile)) {
|
||||||
return fs.readFileSync(versionFile, 'utf8').trim()
|
return fs.readFileSync(versionFile, 'utf8').trim()
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return require('../../package.json').version
|
return require('../../package.json').version
|
||||||
} catch {}
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
return '1.0.0'
|
return '1.0.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ async function sendStreamTestRequest(options) {
|
|||||||
* @param {number} options.maxTokens - 最大输出 token(默认 100)
|
* @param {number} options.maxTokens - 最大输出 token(默认 100)
|
||||||
* @returns {object} 测试请求体
|
* @returns {object} 测试请求体
|
||||||
*/
|
*/
|
||||||
function createGeminiTestPayload(model = 'gemini-2.5-pro', options = {}) {
|
function createGeminiTestPayload(_model = 'gemini-2.5-pro', options = {}) {
|
||||||
const { prompt = 'hi', maxTokens = 100 } = options
|
const { prompt = 'hi', maxTokens = 100 } = options
|
||||||
return {
|
return {
|
||||||
contents: [
|
contents: [
|
||||||
|
|||||||
Reference in New Issue
Block a user