From 534fbf6ac2eb9f0b03162dbc9d48819c5f2cde52 Mon Sep 17 00:00:00 2001 From: Guccbai <1456714872@qq.com> Date: Tue, 23 Dec 2025 20:26:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(eslint):=20=E4=BF=AE=E5=A4=8D=20ESLint=20?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 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 --- src/routes/openaiGeminiRoutes.js | 2 -- src/services/apiKeyService.js | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/routes/openaiGeminiRoutes.js b/src/routes/openaiGeminiRoutes.js index 70795d9e..82b76b95 100644 --- a/src/routes/openaiGeminiRoutes.js +++ b/src/routes/openaiGeminiRoutes.js @@ -499,7 +499,6 @@ router.post('/v1/chat/completions', authenticateApiKey, async (req, res) => { // 记录使用统计 if (!usageReported && totalUsage.totalTokenCount > 0) { try { - const apiKeyService = require('../services/apiKeyService') await apiKeyService.recordUsage( apiKeyData.id, totalUsage.promptTokenCount || 0, @@ -580,7 +579,6 @@ router.post('/v1/chat/completions', authenticateApiKey, async (req, res) => { // 记录使用统计 if (openaiResponse.usage) { try { - const apiKeyService = require('../services/apiKeyService') await apiKeyService.recordUsage( apiKeyData.id, openaiResponse.usage.prompt_tokens || 0, diff --git a/src/services/apiKeyService.js b/src/services/apiKeyService.js index ef3f3b80..771f973b 100644 --- a/src/services/apiKeyService.js +++ b/src/services/apiKeyService.js @@ -43,20 +43,28 @@ const ACCOUNT_CATEGORY_MAP = { * @returns {array} - 权限数组,空数组表示全部服务 */ function normalizePermissions(permissions) { - if (!permissions) return [] // 空 = 全部服务 - if (Array.isArray(permissions)) return permissions + if (!permissions) { + return [] // 空 = 全部服务 + } + if (Array.isArray(permissions)) { + return permissions + } // 尝试解析 JSON 字符串(新格式存储) if (typeof permissions === 'string') { if (permissions.startsWith('[')) { try { const parsed = JSON.parse(permissions) - if (Array.isArray(parsed)) return parsed + if (Array.isArray(parsed)) { + return parsed + } } catch (e) { // 解析失败,继续处理为普通字符串 } } // 旧格式 'all' 转为空数组 - if (permissions === 'all') return [] + if (permissions === 'all') { + return [] + } // 旧单个字符串转为数组 return [permissions] }