fix(eslint): 修复 ESLint 检查错误

- 修复 apiKeyService.js 中 if 语句缺少大括号的 curly 错误
- 移除 openaiGeminiRoutes.js 中重复声明 apiKeyService 导致的 no-shadow 错误

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Guccbai
2025-12-23 20:26:18 +08:00
parent 33ea26f2ac
commit 534fbf6ac2
2 changed files with 12 additions and 6 deletions

View File

@@ -499,7 +499,6 @@ router.post('/v1/chat/completions', authenticateApiKey, async (req, res) => {
// 记录使用统计 // 记录使用统计
if (!usageReported && totalUsage.totalTokenCount > 0) { if (!usageReported && totalUsage.totalTokenCount > 0) {
try { try {
const apiKeyService = require('../services/apiKeyService')
await apiKeyService.recordUsage( await apiKeyService.recordUsage(
apiKeyData.id, apiKeyData.id,
totalUsage.promptTokenCount || 0, totalUsage.promptTokenCount || 0,
@@ -580,7 +579,6 @@ router.post('/v1/chat/completions', authenticateApiKey, async (req, res) => {
// 记录使用统计 // 记录使用统计
if (openaiResponse.usage) { if (openaiResponse.usage) {
try { try {
const apiKeyService = require('../services/apiKeyService')
await apiKeyService.recordUsage( await apiKeyService.recordUsage(
apiKeyData.id, apiKeyData.id,
openaiResponse.usage.prompt_tokens || 0, openaiResponse.usage.prompt_tokens || 0,

View File

@@ -43,20 +43,28 @@ const ACCOUNT_CATEGORY_MAP = {
* @returns {array} - 权限数组,空数组表示全部服务 * @returns {array} - 权限数组,空数组表示全部服务
*/ */
function normalizePermissions(permissions) { function normalizePermissions(permissions) {
if (!permissions) return [] // 空 = 全部服务 if (!permissions) {
if (Array.isArray(permissions)) return permissions return [] // 空 = 全部服务
}
if (Array.isArray(permissions)) {
return permissions
}
// 尝试解析 JSON 字符串(新格式存储) // 尝试解析 JSON 字符串(新格式存储)
if (typeof permissions === 'string') { if (typeof permissions === 'string') {
if (permissions.startsWith('[')) { if (permissions.startsWith('[')) {
try { try {
const parsed = JSON.parse(permissions) const parsed = JSON.parse(permissions)
if (Array.isArray(parsed)) return parsed if (Array.isArray(parsed)) {
return parsed
}
} catch (e) { } catch (e) {
// 解析失败,继续处理为普通字符串 // 解析失败,继续处理为普通字符串
} }
} }
// 旧格式 'all' 转为空数组 // 旧格式 'all' 转为空数组
if (permissions === 'all') return [] if (permissions === 'all') {
return []
}
// 旧单个字符串转为数组 // 旧单个字符串转为数组
return [permissions] return [permissions]
} }