From 7d1cb7b50667443a7c310a3477a4e6ae18f31bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=BB=E5=8B=87=E7=A5=A5?= <237899745@qq.com> Date: Tue, 18 Nov 2025 17:58:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=88=86=E4=BA=ABbug=20-=20=E5=8F=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=AC=AC=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 分享文件夹时,分享链接只显示文件夹内第一个文件 - 原因:前端无论文件还是文件夹都使用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类型:使用'/'(根目录) 测试: - 分享单个文件:正常显示单个文件 - 分享文件夹:正常显示文件夹内所有文件 - 分享所有文件:正常显示根目录所有文件 --- backend/database.js | 16 ++++++++++++++-- frontend/app.js | 10 ++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/backend/database.js b/backend/database.js index 590f354..df52677 100644 --- a/backend/database.js +++ b/backend/database.js @@ -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, diff --git a/frontend/app.js b/frontend/app.js index 1b5bf0d..f3295f8 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -65,6 +65,7 @@ createApp({ shareFileForm: { fileName: "", filePath: "", + isDirectory: false, // 新增:标记是否为文件夹 password: "", expiryType: "never", customDays: 7 @@ -1175,6 +1176,7 @@ handleDragLeave(e) { this.shareFileForm.filePath = this.currentPath === '/' ? file.name : `${this.currentPath}/${file.name}`; + this.shareFileForm.isDirectory = file.isDirectory; // 设置是否为文件夹 this.shareFileForm.password = ''; this.shareFileForm.expiryType = 'never'; this.shareFileForm.customDays = 7; @@ -1215,10 +1217,13 @@ handleDragLeave(e) { this.shareFileForm.expiryType === 'custom' ? this.shareFileForm.customDays : parseInt(this.shareFileForm.expiryType); + // 根据是否为文件夹决定share_type + const shareType = this.shareFileForm.isDirectory ? 'directory' : 'file'; + const response = await axios.post( `${this.apiBase}/api/share/create`, { - share_type: 'file', + share_type: shareType, // 修复:文件夹使用directory类型 file_path: this.shareFileForm.filePath, file_name: this.shareFileForm.fileName, password: this.shareFileForm.password || null, @@ -1229,7 +1234,8 @@ handleDragLeave(e) { if (response.data.success) { this.shareResult = response.data; - this.showToast('success', '成功', '文件分享链接已创建'); + const itemType = this.shareFileForm.isDirectory ? '文件夹' : '文件'; + this.showToast('success', '成功', `${itemType}分享链接已创建`); this.loadShares(); } } catch (error) {