From a4c94b1f68dad2b0fcfcc20fb73bc416e1e2de1d Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Thu, 27 Nov 2025 14:59:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DHTTPS=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=8B=E8=BD=BDHTTP=E7=9B=B4=E9=93=BE=E7=9A=84Mixed?= =?UTF-8?q?=20Content=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - downloadFile: 检测Mixed Content自动降级到后端代理下载 - getMediaUrl: 媒体预览同样处理Mixed Content - 当HTTPS页面遇到HTTP直链时,自动使用服务器代理 - 添加Toast提示用户正在使用代理下载 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/app.html | 2 +- frontend/app.js | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/frontend/app.html b/frontend/app.html index 63d1bf1..0e47f56 100644 --- a/frontend/app.html +++ b/frontend/app.html @@ -2541,6 +2541,6 @@ } - + diff --git a/frontend/app.js b/frontend/app.js index c6dbe58..a3c05fd 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -983,9 +983,28 @@ handleDragLeave(e) { downloadFile(file) { console.log("[DEBUG] 下载文件:", file); - const url = file.httpDownloadUrl - ? file.httpDownloadUrl - : `${this.apiBase}/api/files/download?path=${encodeURIComponent(this.currentPath === '/' ? `/${file.name}` : `${this.currentPath}/${file.name}`)}`; + + // 构建后端代理下载URL + const proxyUrl = `${this.apiBase}/api/files/download?path=${encodeURIComponent(this.currentPath === '/' ? `/${file.name}` : `${this.currentPath}/${file.name}`)}`; + + let url = proxyUrl; + + // 检查是否有HTTP直链可用 + if (file.httpDownloadUrl) { + // 检测Mixed Content:HTTPS页面不能加载HTTP资源 + const isHttpsPage = window.location.protocol === 'https:'; + const isHttpLink = file.httpDownloadUrl.startsWith('http://'); + + if (isHttpsPage && isHttpLink) { + // HTTPS页面 + HTTP直链 = Mixed Content,使用后端代理 + console.log("[DEBUG] 检测到Mixed Content,使用后端代理下载"); + this.showToast('info', '提示', '由于安全限制,正在通过服务器代理下载'); + url = proxyUrl; + } else { + // 可以使用直链 + url = file.httpDownloadUrl; + } + } // 统一通过隐藏链接触发下载,避免弹出新窗口 const link = document.createElement('a'); @@ -1203,13 +1222,25 @@ handleDragLeave(e) { ? `/${file.name}` : `${this.currentPath}/${file.name}`; - // SFTP存储且配置了HTTP下载URL,使用HTTP直接访问;否则使用API下载 + // 构建后端代理URL + const proxyUrl = `${this.apiBase}/api/files/download?path=${encodeURIComponent(filePath)}`; + + // SFTP存储且配置了HTTP下载URL if (file.httpDownloadUrl) { + // 检测Mixed Content:HTTPS页面不能加载HTTP资源 + const isHttpsPage = window.location.protocol === 'https:'; + const isHttpLink = file.httpDownloadUrl.startsWith('http://'); + + if (isHttpsPage && isHttpLink) { + // HTTPS页面 + HTTP直链 = Mixed Content,使用后端代理 + console.log("[DEBUG] 媒体预览检测到Mixed Content,使用后端代理"); + return proxyUrl; + } return file.httpDownloadUrl; } // 本地存储或未配置HTTP URL,使用API下载(同域 Cookie 验证) - return `${this.apiBase}/api/files/download?path=${encodeURIComponent(filePath)}`; + return proxyUrl; }, // 获取文件缩略图URL