update gh-proxy for pass_list
This commit is contained in:
parent
233d5fb0ec
commit
0e12cedf69
|
@ -38,6 +38,7 @@ ASSET_URL = 'https://hunshcn.github.io/gh-proxy' # 主页
|
||||||
|
|
||||||
white_list = [tuple([x.replace(' ', '') for x in i.split('/')]) for i in white_list.split('\n') if i]
|
white_list = [tuple([x.replace(' ', '') for x in i.split('/')]) for i in white_list.split('\n') if i]
|
||||||
black_list = [tuple([x.replace(' ', '') for x in i.split('/')]) for i in black_list.split('\n') if i]
|
black_list = [tuple([x.replace(' ', '') for x in i.split('/')]) for i in black_list.split('\n') if i]
|
||||||
|
pass_list = [tuple([x.replace(' ', '') for x in i.split('/')]) for i in pass_list.split('\n') if i]
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CHUNK_SIZE = 1024 * 10
|
CHUNK_SIZE = 1024 * 10
|
||||||
index_html = requests.get(ASSET_URL, timeout=10).text
|
index_html = requests.get(ASSET_URL, timeout=10).text
|
||||||
|
@ -152,6 +153,11 @@ def handler(u):
|
||||||
else:
|
else:
|
||||||
if exp2.match(u):
|
if exp2.match(u):
|
||||||
u = u.replace('/blob/', '/raw/', 1)
|
u = u.replace('/blob/', '/raw/', 1)
|
||||||
|
if pass_by:
|
||||||
|
url = u + request.url.replace(request.base_url, '', 1)
|
||||||
|
if url.startswith('https:/') and not url.startswith('https://'):
|
||||||
|
url = 'https://' + url[7:]
|
||||||
|
return redirect(url)
|
||||||
return proxy(u)
|
return proxy(u)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ const exp2 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:blob|raw)\/.*$/i
|
||||||
const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i
|
const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i
|
||||||
const exp4 = /^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+?\/.+$/i
|
const exp4 = /^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+?\/.+$/i
|
||||||
const exp5 = /^(?:https?:\/\/)?gist\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+$/i
|
const exp5 = /^(?:https?:\/\/)?gist\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+$/i
|
||||||
|
const exp6 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/tags.*$/i
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any} body
|
* @param {any} body
|
||||||
|
@ -60,7 +61,7 @@ addEventListener('fetch', e => {
|
||||||
|
|
||||||
|
|
||||||
function checkUrl(u) {
|
function checkUrl(u) {
|
||||||
for (let i of [exp1, exp2, exp3, exp4, exp5, ]) {
|
for (let i of [exp1, exp2, exp3, exp4, exp5, exp6 ]) {
|
||||||
if (u.search(i) === 0) {
|
if (u.search(i) === 0) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -81,7 +82,7 @@ async function fetchHandler(e) {
|
||||||
}
|
}
|
||||||
// cfworker 会把路径中的 `//` 合并成 `/`
|
// cfworker 会把路径中的 `//` 合并成 `/`
|
||||||
path = urlObj.href.substr(urlObj.origin.length + PREFIX.length).replace(/^https?:\/+/, 'https://')
|
path = urlObj.href.substr(urlObj.origin.length + PREFIX.length).replace(/^https?:\/+/, 'https://')
|
||||||
if (path.search(exp1) === 0 || path.search(exp5) === 0 || !Config.cnpmjs && (path.search(exp3) === 0 || path.search(exp4) === 0)) {
|
if (path.search(exp1) === 0 || path.search(exp5) === 0 || path.search(exp6) === 0 || !Config.cnpmjs && (path.search(exp3) === 0 || path.search(exp4) === 0)) {
|
||||||
return httpHandler(req, path)
|
return httpHandler(req, path)
|
||||||
} else if (path.search(exp2) === 0) {
|
} else if (path.search(exp2) === 0) {
|
||||||
if (Config.jsdelivr) {
|
if (Config.jsdelivr) {
|
||||||
|
|
Loading…
Reference in New Issue