diff --git a/frontend/app.js b/frontend/app.js index ab377a9..27da683 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -933,25 +933,17 @@ handleDragLeave(e) { downloadFile(file) { console.log("[DEBUG] 下载文件:", file); - if (file.httpDownloadUrl) { - // 如果配置了HTTP下载URL,使用HTTP直接下载 - console.log("[DEBUG] 使用HTTP下载:", file.httpDownloadUrl); - window.open(file.httpDownloadUrl, "_blank"); - } else { - // 如果没有配置HTTP URL,通过后端SFTP下载 - console.log("[DEBUG] 使用SFTP下载"); - const filePath = this.currentPath === '/' - ? `/${file.name}` - : `${this.currentPath}/${file.name}`; + const url = file.httpDownloadUrl + ? file.httpDownloadUrl + : `${this.apiBase}/api/files/download?path=${encodeURIComponent(this.currentPath === '/' ? `/${file.name}` : `${this.currentPath}/${file.name}`)}`; - // 使用标签下载,依赖同域 Cookie/凭证 - const link = document.createElement('a'); - link.href = `${this.apiBase}/api/files/download?path=${encodeURIComponent(filePath)}`; - link.setAttribute('download', file.name); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - } + // 统一通过隐藏链接触发下载,避免弹出新窗口 + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', file.name); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); }, // ===== 文件操作 =====