fix: 修复文件夹右键菜单问题 + 新增文件夹详情功能

修复内容:

1. 【文件夹右键菜单无法显示】
   - 问题: showFileContextMenu() 中仍有 `if (file.isDirectory) return` 阻止代码
   - 原因: 之前的修复脚本替换失败,代码仍在
   - 修复: 手动移除这行限制代码
   - 效果: 文件夹现在可以正常右键操作(重命名、删除、查看详情)

新功能:

2. 【文件夹详情查看】
   后端API (POST /api/files/folder-info):
   - 接收参数: path(当前路径), folderName(文件夹名称)
   - 计算文件夹总大小(递归统计所有文件)
   - 统计文件数量和子文件夹数量
   - 返回数据: name, path, size, fileCount, folderCount
   - 仅支持本地存储

   前端功能:
   - 右键菜单新增"查看详情"选项(仅文件夹显示)
   - 详情弹窗显示:
     * 文件夹名称
     * 文件夹路径
     * 总大小(格式化显示)
     * 文件数量
     * 子文件夹数量
   - 加载中状态提示
   - 错误处理和提示

使用方式:
1. 右键点击任意文件夹
2. 选择"查看详情"
3. 弹窗显示文件夹统计信息

技术改动:
- backend/server.js: +100行 (新增folder-info API)
- frontend/app.html: +40行 (详情弹窗UI + 菜单项)
- frontend/app.js: +30行 (状态 + showFolderInfo方法)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
WanWanYun
2025-11-16 00:07:21 +08:00
parent 560b90f7f7
commit f64f86cd78
3 changed files with 177 additions and 4 deletions

View File

@@ -1133,6 +1133,101 @@ app.post('/api/files/mkdir', authMiddleware, async (req, res) => {
}
});
// 获取文件夹详情(大小统计)
app.post('/api/files/folder-info', authMiddleware, async (req, res) => {
const { path, folderName } = req.body;
let storage;
if (!folderName) {
return res.status(400).json({
success: false,
message: '缺少文件夹名称参数'
});
}
// 只支持本地存储
if (req.user.current_storage_type !== 'local') {
return res.status(400).json({
success: false,
message: '只有本地存储支持此功能'
});
}
try {
const { StorageInterface } = require('./storage');
const storageInterface = new StorageInterface(req.user);
storage = await storageInterface.connect();
// 构造文件夹路径
const basePath = path || '/';
const folderPath = basePath === '/' ? `/${folderName}` : `${basePath}/${folderName}`;
const fullPath = storage.getFullPath(folderPath);
// 检查是否存在且是文件夹
if (!fs.existsSync(fullPath)) {
return res.status(404).json({
success: false,
message: '文件夹不存在'
});
}
const stats = fs.statSync(fullPath);
if (!stats.isDirectory()) {
return res.status(400).json({
success: false,
message: '指定路径不是文件夹'
});
}
// 计算文件夹大小
const folderSize = storage.calculateFolderSize(fullPath);
// 计算文件数量
function countFiles(dirPath) {
let fileCount = 0;
let folderCount = 0;
const items = fs.readdirSync(dirPath, { withFileTypes: true });
for (const item of items) {
const itemPath = path.join(dirPath, item.name);
if (item.isDirectory()) {
folderCount++;
const subCounts = countFiles(itemPath);
fileCount += subCounts.fileCount;
folderCount += subCounts.folderCount;
} else {
fileCount++;
}
}
return { fileCount, folderCount };
}
const counts = countFiles(fullPath);
res.json({
success: true,
data: {
name: folderName,
path: folderPath,
size: folderSize,
fileCount: counts.fileCount,
folderCount: counts.folderCount
}
});
} catch (error) {
console.error('[获取文件夹详情失败]', error);
res.status(500).json({
success: false,
message: '获取文件夹详情失败: ' + error.message
});
} finally {
if (storage) await storage.end();
}
});
// 删除文件
app.post('/api/files/delete', authMiddleware, async (req, res) => {
const { fileName, path } = req.body;