From eaf9ad7bb17514f0a06fdfdfa09e825acaabcf52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=BB=E5=8B=87=E7=A5=A5?= <237899745@qq.com> Date: Fri, 14 Nov 2025 16:09:01 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E6=B7=BB=E5=8A=A0=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E7=9A=84=E5=88=86=E4=BA=AB=E9=AA=8C=E8=AF=81=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 调试内容 为了排查过期分享仍能访问的问题,添加了详细的调试日志: ### 1. database.js - ShareDB.findByCode() - 记录调用时的参数和SQLite当前时间 - 记录SQL查询结果(是否找到、过期时间、分享类型) - 便于对比JavaScript时间和SQLite时间 ### 2. server.js - /api/share/:code/verify - 记录请求时间戳、分享码、是否有密码、请求IP - 记录findByCode的返回结果和过期状态 ### 3. server.js - /api/share/:code/list - 记录请求时间戳、分享码、子路径、密码状态 - 记录findByCode的返回结果和过期状态 ## 使用方法 1. 管理员在管理后台开启调试模式 2. 访问分享链接 https://cs.workyai.cn/s/oSrhV9D3 3. 查看后端console日志输出 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- backend/database.js | 20 +++++++++++++++++++- backend/server.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/backend/database.js b/backend/database.js index 0a5c591..6667532 100644 --- a/backend/database.js +++ b/backend/database.js @@ -333,13 +333,31 @@ const ShareDB = { // 根据分享码查找 findByCode(shareCode) { - return db.prepare(` + // 调试日志: findByCode 调用 + const currentTime = db.prepare("SELECT datetime('now') as now").get(); + console.log('[ShareDB.findByCode]', { + shareCode, + currentTime: currentTime.now, + timestamp: new Date().toISOString() + }); + + const result = db.prepare(` SELECT s.*, u.username, u.ftp_host, u.ftp_port, u.ftp_user, u.ftp_password, u.http_download_base_url FROM shares s JOIN users u ON s.user_id = u.id WHERE s.share_code = ? AND (s.expires_at IS NULL OR s.expires_at > datetime('now')) `).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; }, // 根据ID查找 diff --git a/backend/server.js b/backend/server.js index 13a8a66..1fc94af 100644 --- a/backend/server.js +++ b/backend/server.js @@ -1582,8 +1582,26 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) = let storage; 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, @@ -1743,8 +1761,27 @@ app.post('/api/share/:code/list', shareRateLimitMiddleware, async (req, res) => let storage; try { + + // ===== 调试日志: 获取分享文件列表 ===== + console.log('[获取文件列表]', { + timestamp: new Date().toISOString(), + shareCode: code, + subPath: subPath, + 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,