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) {