🐛 修复文件夹分享bug - 只显示第一个文件的问题
问题:
- 分享文件夹时,分享链接只显示文件夹内第一个文件
- 原因:前端无论文件还是文件夹都使用share_type='file'
- 后端对非file类型的分享路径处理不正确
修复方案:
1. 前端修改(frontend/app.js):
- shareFileForm添加isDirectory字段标记是否为文件夹
- openShareFileModal设置isDirectory值
- createShareFile根据isDirectory设置正确的share_type
* 文件: share_type='file'
* 文件夹: share_type='directory'
2. 后端修改(backend/database.js):
- 修复ShareDB.create中的sharePath逻辑
- file类型:使用file_path(单文件路径)
- directory类型:使用file_path(文件夹路径)
- all类型:使用'/'(根目录)
测试:
- 分享单个文件:正常显示单个文件
- 分享文件夹:正常显示文件夹内所有文件
- 分享所有文件:正常显示根目录所有文件
This commit is contained in:
@@ -320,8 +320,20 @@ const ShareDB = {
|
||||
`);
|
||||
|
||||
const hashedPassword = password ? bcrypt.hashSync(password, 10) : null;
|
||||
const sharePath = share_type === 'file' ? file_path : '/';
|
||||
|
||||
|
||||
// 修复:正确处理不同类型的分享路径
|
||||
let sharePath;
|
||||
if (share_type === 'file') {
|
||||
// 单文件分享:使用完整文件路径
|
||||
sharePath = file_path;
|
||||
} else if (share_type === 'directory') {
|
||||
// 文件夹分享:使用文件夹路径
|
||||
sharePath = file_path;
|
||||
} else {
|
||||
// all类型:分享根目录
|
||||
sharePath = '/';
|
||||
}
|
||||
|
||||
const result = stmt.run(
|
||||
userId,
|
||||
shareCode,
|
||||
|
||||
Reference in New Issue
Block a user