fix(proxy): 更换代理服务为 allorigins.win 并更新处理逻辑
更新代理配置从自定义代理服务改为使用 allorigins.win 服务,并相应修改代理请求处理逻辑。当代理请求失败时,自动回退到直接请求方式。同时移除了未使用的 Google AdSense 脚本。
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
// 图片代理处理器
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
content="%VITE_GOOGLE_SEARCH_CONSOLE_VERIFICATION%"
|
||||
/>
|
||||
<!-- Google AdSense -->
|
||||
<script
|
||||
<!-- <script
|
||||
async
|
||||
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=%VITE_ADSENSE_PUB_ID%"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
></script> -->
|
||||
<!-- jQuery -->
|
||||
<!-- <script src="https://unpkg.com/jquery@3.7.1/dist/jquery.js"></script> -->
|
||||
</head>
|
||||
|
||||
@@ -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/"
|
||||
|
||||
Reference in New Issue
Block a user