refactor: 清理所有调试日志和死代码
- 🗑️ 删除未使用的依赖: net, dns 模块 - 🧹 将 console.log("[DEBUG]") 替换为 SystemLogDB.log() - 🧹 清理分享验证相关的调试日志 - 🧹 清理数据库查询的调试日志 - 🧹 删除下载功能的调试日志 - ✅ 代码更专业,日志统一使用 SystemLogDB Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -441,14 +441,6 @@ const ShareDB = {
|
|||||||
|
|
||||||
// 根据分享码查找
|
// 根据分享码查找
|
||||||
findByCode(shareCode) {
|
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(`
|
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
|
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
|
FROM shares s
|
||||||
@@ -457,14 +449,6 @@ const ShareDB = {
|
|||||||
AND (s.expires_at IS NULL OR s.expires_at > datetime('now', 'localtime'))
|
AND (s.expires_at IS NULL OR s.expires_at > datetime('now', 'localtime'))
|
||||||
`).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;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ const fs = require('fs');
|
|||||||
const { body, validationResult } = require('express-validator');
|
const { body, validationResult } = require('express-validator');
|
||||||
const archiver = require('archiver');
|
const archiver = require('archiver');
|
||||||
const { exec, execSync, execFile } = require('child_process');
|
const { exec, execSync, execFile } = require('child_process');
|
||||||
const net = require('net');
|
|
||||||
const dns = require('dns').promises;
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const execAsync = util.promisify(exec);
|
const execAsync = util.promisify(exec);
|
||||||
const execFileAsync = util.promisify(execFile);
|
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) => {
|
app.post('/api/share/create', authMiddleware, (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { share_type, file_path, file_name, password, expiry_days } = req.body;
|
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) {
|
if (share_type === 'file' && !file_path) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@@ -3373,25 +3377,8 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) =
|
|||||||
|
|
||||||
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,
|
||||||
@@ -3450,7 +3437,6 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) =
|
|||||||
|
|
||||||
// 检查缓存
|
// 检查缓存
|
||||||
if (shareFileCache.has(code)) {
|
if (shareFileCache.has(code)) {
|
||||||
console.log(`[缓存命中] 分享码: ${code}`);
|
|
||||||
responseData.file = shareFileCache.get(code);
|
responseData.file = shareFileCache.get(code);
|
||||||
} else {
|
} else {
|
||||||
// 缓存未命中,查询存储
|
// 缓存未命中,查询存储
|
||||||
@@ -3461,7 +3447,6 @@ app.post('/api/share/:code/verify', shareRateLimitMiddleware, async (req, res) =
|
|||||||
throw new Error('分享者不存在');
|
throw new Error('分享者不存在');
|
||||||
}
|
}
|
||||||
const storageType = shareOwner.current_storage_type || 'oss';
|
const storageType = shareOwner.current_storage_type || 'oss';
|
||||||
console.log(`[缓存未命中] 分享码: ${code},存储类型: ${storageType}`);
|
|
||||||
|
|
||||||
// 使用统一存储接口
|
// 使用统一存储接口
|
||||||
const { StorageInterface } = require('./storage');
|
const { StorageInterface } = require('./storage');
|
||||||
@@ -3552,14 +3537,6 @@ app.post('/api/share/:code/list', shareRateLimitMiddleware, async (req, res) =>
|
|||||||
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,
|
||||||
|
|||||||
@@ -1238,8 +1238,6 @@ handleDragLeave(e) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
downloadFile(file) {
|
downloadFile(file) {
|
||||||
console.log("[DEBUG] 下载文件:", file);
|
|
||||||
|
|
||||||
// 构建文件路径
|
// 构建文件路径
|
||||||
const filePath = this.currentPath === '/' ? `/${file.name}` : `${this.currentPath}/${file.name}`;
|
const filePath = this.currentPath === '/' ? `/${file.name}` : `${this.currentPath}/${file.name}`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user