From 46b06a9617c1257a22ca7a3c256e5f74dba32702 Mon Sep 17 00:00:00 2001 From: hymbz Date: Fri, 23 Aug 2024 16:24:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=BD=91=E7=AB=99=E6=97=A0=E6=B3=95=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=BC=AB=E7=94=BB=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/userscript/main/request.ts | 2 +- src/userscript/useComponents/DownloadButton.tsx | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/userscript/main/request.ts b/src/userscript/main/request.ts index f9104d8f..89008693 100644 --- a/src/userscript/main/request.ts +++ b/src/userscript/main/request.ts @@ -45,7 +45,7 @@ export const request = async ( // 为了支持 ios 端只能自己实现一下了 if ( details?.fetch ?? - (/^(\/|blob:)/.test(url) || url.startsWith(window.location.origin)) + (url.startsWith('/') || url.startsWith(window.location.origin)) ) { const res = await fetch(url, { method: 'GET', diff --git a/src/userscript/useComponents/DownloadButton.tsx b/src/userscript/useComponents/DownloadButton.tsx index 33084ad7..aba70328 100644 --- a/src/userscript/useComponents/DownloadButton.tsx +++ b/src/userscript/useComponents/DownloadButton.tsx @@ -9,14 +9,18 @@ import { request } from '../main/request'; import { toast } from './Toast'; -const Accept = - 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8'; - /** 下载按钮 */ export const DownloadButton = () => { const [statu, setStatu] = createSignal('button.download'); const handleDownload = async () => { + const headers = { + Accept: + 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8', + 'User-Agent': navigator.userAgent, + Referer: window.location.href, + }; + const fileData: Zippable = {}; const { imgList } = store; @@ -41,7 +45,7 @@ export const DownloadButton = () => { let fileName: string; try { const res = await request(url, { - headers: { Accept }, + headers, responseType: 'blob', errorText: `${t('alert.download_failed')}: ${index}`, });