From f89835578c98a3544b21a6cce0fd1eb7fc5b5c88 Mon Sep 17 00:00:00 2001 From: xlsea Date: Sat, 26 Jul 2025 12:43:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(hooks):=20=E9=9D=9E=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E4=B8=8D=E4=BD=BF=E7=94=A8=E6=B5=81?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/business/download.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hooks/business/download.ts b/src/hooks/business/download.ts index 060b4579..866aa78a 100644 --- a/src/hooks/business/download.ts +++ b/src/hooks/business/download.ts @@ -16,6 +16,12 @@ export function useDownload() { const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y'; const { baseURL } = getServiceBaseURL(import.meta.env, isHttpProxy); + const isHttps = () => { + const protocol = document.location.protocol; + const hostname = document.location.hostname; + return protocol === 'https' || hostname === 'localhost' || hostname === '127.0.0.1'; + }; + /** 获取通用请求头 */ const getCommonHeaders = (contentType = 'application/octet-stream') => ({ Authorization: `Bearer ${localStg.get('token')}`, @@ -111,7 +117,7 @@ export function useDownload() { const finalFilename = filename || response.headers.get('Download-Filename') || `download-${timestamp}`; - if (response.body) { + if (response.body && isHttps()) { const contentLength = Number(response.headers.get('Content-Length')); await downloadByStream(response.body, finalFilename, contentLength); return;