🐛 修复文件夹分享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 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(
|
const result = stmt.run(
|
||||||
userId,
|
userId,
|
||||||
shareCode,
|
shareCode,
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ createApp({
|
|||||||
shareFileForm: {
|
shareFileForm: {
|
||||||
fileName: "",
|
fileName: "",
|
||||||
filePath: "",
|
filePath: "",
|
||||||
|
isDirectory: false, // 新增:标记是否为文件夹
|
||||||
password: "",
|
password: "",
|
||||||
expiryType: "never",
|
expiryType: "never",
|
||||||
customDays: 7
|
customDays: 7
|
||||||
@@ -1175,6 +1176,7 @@ handleDragLeave(e) {
|
|||||||
this.shareFileForm.filePath = this.currentPath === '/'
|
this.shareFileForm.filePath = this.currentPath === '/'
|
||||||
? file.name
|
? file.name
|
||||||
: `${this.currentPath}/${file.name}`;
|
: `${this.currentPath}/${file.name}`;
|
||||||
|
this.shareFileForm.isDirectory = file.isDirectory; // 设置是否为文件夹
|
||||||
this.shareFileForm.password = '';
|
this.shareFileForm.password = '';
|
||||||
this.shareFileForm.expiryType = 'never';
|
this.shareFileForm.expiryType = 'never';
|
||||||
this.shareFileForm.customDays = 7;
|
this.shareFileForm.customDays = 7;
|
||||||
@@ -1215,10 +1217,13 @@ handleDragLeave(e) {
|
|||||||
this.shareFileForm.expiryType === 'custom' ? this.shareFileForm.customDays :
|
this.shareFileForm.expiryType === 'custom' ? this.shareFileForm.customDays :
|
||||||
parseInt(this.shareFileForm.expiryType);
|
parseInt(this.shareFileForm.expiryType);
|
||||||
|
|
||||||
|
// 根据是否为文件夹决定share_type
|
||||||
|
const shareType = this.shareFileForm.isDirectory ? 'directory' : 'file';
|
||||||
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${this.apiBase}/api/share/create`,
|
`${this.apiBase}/api/share/create`,
|
||||||
{
|
{
|
||||||
share_type: 'file',
|
share_type: shareType, // 修复:文件夹使用directory类型
|
||||||
file_path: this.shareFileForm.filePath,
|
file_path: this.shareFileForm.filePath,
|
||||||
file_name: this.shareFileForm.fileName,
|
file_name: this.shareFileForm.fileName,
|
||||||
password: this.shareFileForm.password || null,
|
password: this.shareFileForm.password || null,
|
||||||
@@ -1229,7 +1234,8 @@ handleDragLeave(e) {
|
|||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
this.shareResult = response.data;
|
this.shareResult = response.data;
|
||||||
this.showToast('success', '成功', '文件分享链接已创建');
|
const itemType = this.shareFileForm.isDirectory ? '文件夹' : '文件';
|
||||||
|
this.showToast('success', '成功', `${itemType}分享链接已创建`);
|
||||||
this.loadShares();
|
this.loadShares();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user