From 0e12cedf692a3bf3b803b2a46e29a00c37870c37 Mon Sep 17 00:00:00 2001 From: Stille Date: Fri, 21 Jan 2022 23:33:07 +0800 Subject: [PATCH] update gh-proxy for pass_list --- gh-proxy/app/main.py | 6 ++++++ gh-proxy/index.js | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gh-proxy/app/main.py b/gh-proxy/app/main.py index 7d0216b..808e030 100644 --- a/gh-proxy/app/main.py +++ b/gh-proxy/app/main.py @@ -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] 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__) CHUNK_SIZE = 1024 * 10 index_html = requests.get(ASSET_URL, timeout=10).text @@ -152,6 +153,11 @@ def handler(u): else: if exp2.match(u): 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) diff --git a/gh-proxy/index.js b/gh-proxy/index.js index 29a7212..2c7b21e 100644 --- a/gh-proxy/index.js +++ b/gh-proxy/index.js @@ -28,6 +28,7 @@ const exp2 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:blob|raw)\/.*$/i const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i const exp4 = /^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+?\/.+$/i const exp5 = /^(?:https?:\/\/)?gist\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+$/i +const exp6 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/tags.*$/i /** * @param {any} body @@ -60,7 +61,7 @@ addEventListener('fetch', e => { 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) { return true } @@ -81,7 +82,7 @@ async function fetchHandler(e) { } // cfworker 会把路径中的 `//` 合并成 `/` 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) } else if (path.search(exp2) === 0) { if (Config.jsdelivr) {