debug: 添加详细的分享验证调试日志

## 调试内容
为了排查过期分享仍能访问的问题,添加了详细的调试日志:

### 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 <noreply@anthropic.com>
This commit is contained in:
2025-11-14 16:09:01 +08:00
parent bce225ec5c
commit eaf9ad7bb1
2 changed files with 56 additions and 1 deletions

View File

@@ -333,13 +333,31 @@ const ShareDB = {
// 根据分享码查找 // 根据分享码查找
findByCode(shareCode) { 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 SELECT s.*, u.username, u.ftp_host, u.ftp_port, u.ftp_user, u.ftp_password, u.http_download_base_url
FROM shares s FROM shares s
JOIN users u ON s.user_id = u.id JOIN users u ON s.user_id = u.id
WHERE s.share_code = ? WHERE s.share_code = ?
AND (s.expires_at IS NULL OR s.expires_at > datetime('now')) AND (s.expires_at IS NULL OR s.expires_at > datetime('now'))
`).get(shareCode); `).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查找 // 根据ID查找

View File

@@ -1582,8 +1582,26 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) =
let storage; let storage;
try { try {
// ===== 调试日志: 分享验证开始 =====
console.log('[分享验证]', {
timestamp: new Date().toISOString(),
shareCode: code,
hasPassword: !!password,
requestIP: req.ip
});
const share = ShareDB.findByCode(code); 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) { if (!share) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
@@ -1743,8 +1761,27 @@ app.post('/api/share/:code/list', shareRateLimitMiddleware, async (req, res) =>
let storage; let storage;
try { try {
// ===== 调试日志: 获取分享文件列表 =====
console.log('[获取文件列表]', {
timestamp: new Date().toISOString(),
shareCode: code,
subPath: subPath,
hasPassword: !!password,
requestIP: req.ip
});
const share = ShareDB.findByCode(code); 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) { if (!share) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,