31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
export default {
|
||
async fetch(request) {
|
||
const url = new URL(request.url);
|
||
const { hostname, pathname, search } = url;
|
||
if (checkUrl(pathname)) {
|
||
return fetch(new Request("https://github.com" + pathname + search, {
|
||
body: request.body,
|
||
headers: request.headers,
|
||
method: request.method,
|
||
redirect: request.redirect
|
||
}));
|
||
} else {
|
||
let tip = `GitHub 下载代理,支持 releases、archive、tags、raw 等。
|
||
|
||
使用方法:将 Github 原链接中的 【github.com】 改为 【${hostname}】。
|
||
如:【https://github.com/a/a/releases】改为【https://${hostname}/a/a/releases】。`
|
||
return new Response(tip);
|
||
}
|
||
}
|
||
};
|
||
|
||
function checkUrl(u) {
|
||
const exp1 = "/.+?\/.+?\/(?:releases|archive|tags).*"
|
||
const exp2 = "/.+?\/.+?\/raw\/.*"
|
||
for (let ind of [exp1, exp2]) {
|
||
if (u.search(ind) === 0) {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
} |