From ebf6833e70a8e45da579d4bb9e72ef60a024dd2b Mon Sep 17 00:00:00 2001 From: JuLuogo <1576586736@qq.com> Date: Wed, 8 Oct 2025 17:37:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(proxy):=20=E6=9B=B4=E6=8D=A2=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=9C=8D=E5=8A=A1=E4=B8=BA=20allorigins.win=20?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新代理配置从自定义代理服务改为使用 allorigins.win 服务,并相应修改代理请求处理逻辑。当代理请求失败时,自动回退到直接请求方式。同时移除了未使用的 Google AdSense 脚本。 --- functions/[[path]].ts | 52 ++++++++++++++++++++++++++++++------------- index.html | 4 ++-- wrangler.toml | 2 +- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/functions/[[path]].ts b/functions/[[path]].ts index 81ba0d8..0870aa4 100644 --- a/functions/[[path]].ts +++ b/functions/[[path]].ts @@ -281,23 +281,45 @@ async function handleGenericProxy(request: Request, env: any) { // 如果配置了代理IP,则通过代理发送请求 if (env.PROXY_IP) { - const proxyUrl = `https://${env.PROXY_IP}/${url.toString()}` - const newReq = new Request(proxyUrl, { - method: request.method, - headers, - body: request.body, + // 使用 allorigins.win 代理服务 + const proxyUrl = `https://${env.PROXY_IP}?get=${encodeURIComponent(url.toString())}` + const proxyReq = new Request(proxyUrl, { + method: 'GET', // allorigins.win 只支持 GET 请求 + headers: { + 'User-Agent': env.USER_AGENT || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0' + } }) - const response = await fetch(newReq) - return corsResponse(response) - } else { - const newReq = new Request(url.toString(), { - method: request.method, - headers, - body: request.body, - }) - const response = await fetch(newReq) - return corsResponse(response) + + try { + const proxyResponse = await fetch(proxyReq) + if (!proxyResponse.ok) { + throw new Error(`Proxy returned ${proxyResponse.status}`) + } + + const proxyData = await proxyResponse.json() + if (proxyData.contents) { + // 解析代理返回的内容 + const pixivData = JSON.parse(proxyData.contents) + return corsResponse(new Response(JSON.stringify(pixivData), { + headers: { 'Content-Type': 'application/json' } + })) + } else { + throw new Error('No contents in proxy response') + } + } catch (error) { + console.error('Proxy request failed:', error) + // 如果代理失败,回退到直接请求 + } } + + // 直接请求或代理失败时的回退 + const newReq = new Request(url.toString(), { + method: request.method, + headers, + body: request.body, + }) + const response = await fetch(newReq) + return corsResponse(response) } // 图片代理处理器 diff --git a/index.html b/index.html index c5462b7..809b4da 100644 --- a/index.html +++ b/index.html @@ -27,11 +27,11 @@ content="%VITE_GOOGLE_SEARCH_CONSOLE_VERIFICATION%" /> - + > --> diff --git a/wrangler.toml b/wrangler.toml index f297f8c..8deff7f 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -12,7 +12,7 @@ bucket = "./dist" # User-Agent 黑名单(JSON 数组格式) # 代理IP配置(可选,用于绕过Pixiv WAF) -PROXY_IP = "ProxyIP.US.CMLiussss.net" +PROXY_IP = "api.allorigins.win/get?url=" # 自定义图片代理 URL(可选,默认使用 Pixiv 原始 URL) # 示例配置: # VITE_PXIMG_BASEURL_I = "https://i.pixiv.re/"