我这里的解决方法是用cloudflare workers做了一个镜像代理
mirror.biliwind.com
使用方法
只需要将下载地址拼接到这个代理url后面即可,例如我要从GitHub下载MCSM的安装包
https://mirror.biliwind.com/https://github.com/MCSManager/MCSManager/releases/latest/download/mcsmanager_linux_release.tar.gz
注意:这只是国内无法访问GitHub等网站时的临时解决方案,如果你本地有网络代理类软件或学术加速器,可以先下载到本地再上传服务器
扩展用途
如果你直接访问mirror.biliwind.com,那么会看到一个输入框和一个“Go”按钮,你可以输入任何网址(必须完整,即带有http:// 或https:// ,否则报错
这时加速GitHub的例子:
代码开源
如果你想自建代理,请将下面的“mirror.biliwind.com替换为你绑定在workers的域名
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const { pathname, searchParams } = new URL(request.url)
if (pathname === '/') {
// 返回带有输入框的 HTML 页面
return new Response('<input type="text" id="urlInput"><button onclick="redirect()">Go</button><script>function redirect() { const url = document.getElementById("urlInput").value; window.location.href = "https://mirror.biliwind.com/" + encodeURIComponent(url); }</script>', {
headers: { 'Content-Type': 'text/html' }
})
} else {
// 获取要访问的网页链接
const url = decodeURIComponent(pathname.slice(1))
// 反向代理访问网页
const response = await fetch(url, request)
// 如果响应是301或302重定向
if (response.status === 301 || response.status === 302) {
const redirectUrl = response.headers.get('Location')
// 生成重定向的 URL
const newUrl = `https://mirror.biliwind.com/${encodeURIComponent(redirectUrl)}`
// 创建一个新的请求
const newRequest = new Request(newUrl, request)
return handleRequest(newRequest)
}
// 将响应返回给用户
return new Response(response.body, response)
}
}