From 92b70a11d71615becfc8accdfd87f0c2eceb54d1 Mon Sep 17 00:00:00 2001 From: Claude Opus Date: Sun, 18 Jan 2026 18:09:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B8=85=E7=90=86=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E5=92=8C=E6=AD=BB?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 🗑️ 删除未使用的依赖: net, dns 模块 - 🧹 将 console.log("[DEBUG]") 替换为 SystemLogDB.log() - 🧹 清理分享验证相关的调试日志 - 🧹 清理数据库查询的调试日志 - 🧹 删除下载功能的调试日志 - ✅ 代码更专业,日志统一使用 SystemLogDB Co-Authored-By: Claude Opus 4.5 --- backend/database.js | 16 ---------------- backend/server.js | 37 +++++++------------------------------ frontend/app.js | 2 -- 3 files changed, 7 insertions(+), 48 deletions(-) diff --git a/backend/database.js b/backend/database.js index 063ccd1..8e18574 100644 --- a/backend/database.js +++ b/backend/database.js @@ -441,14 +441,6 @@ const ShareDB = { // 根据分享码查找 findByCode(shareCode) { - // 调试日志: findByCode 调用 - const currentTime = db.prepare("SELECT datetime('now', 'localtime') as now").get(); - console.log('[ShareDB.findByCode]', { - shareCode, - currentTime: currentTime.now, - timestamp: new Date().toISOString() - }); - const result = db.prepare(` SELECT s.*, u.username, u.oss_provider, u.oss_region, u.oss_access_key_id, u.oss_access_key_secret, u.oss_bucket, u.oss_endpoint, u.theme_preference FROM shares s @@ -457,14 +449,6 @@ const ShareDB = { AND (s.expires_at IS NULL OR s.expires_at > datetime('now', 'localtime')) `).get(shareCode); - // 调试日志: SQL查询结果 - console.log('[ShareDB.findByCode] SQL结果:', { - found: !!result, - shareCode: result?.share_code || null, - expires_at: result?.expires_at || null, - share_type: result?.share_type || null - }); - return result; }, diff --git a/backend/server.js b/backend/server.js index 883f79a..8303948 100644 --- a/backend/server.js +++ b/backend/server.js @@ -13,8 +13,6 @@ const fs = require('fs'); const { body, validationResult } = require('express-validator'); const archiver = require('archiver'); const { exec, execSync, execFile } = require('child_process'); -const net = require('net'); -const dns = require('dns').promises; const util = require('util'); const execAsync = util.promisify(exec); const execFileAsync = util.promisify(execFile); @@ -3208,7 +3206,13 @@ app.post('/api/upload/get-config', async (req, res) => { app.post('/api/share/create', authMiddleware, (req, res) => { try { const { share_type, file_path, file_name, password, expiry_days } = req.body; - console.log("[DEBUG] 创建分享请求:", { share_type, file_path, file_name, password: password ? "***" : null, expiry_days }); + SystemLogDB.log({ + level: 'info', + category: 'share', + action: 'create_share', + message: '创建分享请求', + details: { share_type, file_path, file_name, expiry_days } + }); if (share_type === 'file' && !file_path) { return res.status(400).json({ @@ -3373,25 +3377,8 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) = try { - // ===== 调试日志: 分享验证开始 ===== - console.log('[分享验证]', { - timestamp: new Date().toISOString(), - shareCode: code, - hasPassword: !!password, - requestIP: req.ip - }); - const share = ShareDB.findByCode(code); - - // 调试日志: findByCode 结果 - console.log('[分享验证] findByCode结果:', { - found: !!share, - expires_at: share?.expires_at || null, - current_time: new Date().toISOString(), - is_expired: share?.expires_at ? new Date(share.expires_at) <= new Date() : false - }); - if (!share) { return res.status(404).json({ success: false, @@ -3450,7 +3437,6 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) = // 检查缓存 if (shareFileCache.has(code)) { - console.log(`[缓存命中] 分享码: ${code}`); responseData.file = shareFileCache.get(code); } else { // 缓存未命中,查询存储 @@ -3461,7 +3447,6 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) = throw new Error('分享者不存在'); } const storageType = shareOwner.current_storage_type || 'oss'; - console.log(`[缓存未命中] 分享码: ${code},存储类型: ${storageType}`); // 使用统一存储接口 const { StorageInterface } = require('./storage'); @@ -3552,14 +3537,6 @@ app.post('/api/share/:code/list', shareRateLimitMiddleware, async (req, res) => const share = ShareDB.findByCode(code); - // 调试日志: findByCode 结果 - console.log('[获取文件列表] findByCode结果:', { - found: !!share, - expires_at: share?.expires_at || null, - current_time: new Date().toISOString(), - is_expired: share?.expires_at ? new Date(share.expires_at) <= new Date() : false - }); - if (!share) { return res.status(404).json({ success: false, diff --git a/frontend/app.js b/frontend/app.js index 1ed67ea..918a8f7 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -1238,8 +1238,6 @@ handleDragLeave(e) { }, downloadFile(file) { - console.log("[DEBUG] 下载文件:", file); - // 构建文件路径 const filePath = this.currentPath === '/' ? `/${file.name}` : `${this.currentPath}/${file.name}`;