From a2424010f11fe9e287f8485ffdbe27d4d23a4e4b Mon Sep 17 00:00:00 2001 From: fcying Date: Sun, 26 Dec 2021 10:59:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5redirtype,=20=E6=8C=87?= =?UTF-8?q?=E5=AE=9Aurl=E4=B8=8D=E4=BD=BF=E7=94=A8=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index cad96de..bf35c6c 100644 --- a/index.js +++ b/index.js @@ -70,15 +70,19 @@ async function fetchHandler(e) { const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i const exp4 = /^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+?\/.+$/i const exp5 = /^(?:https?:\/\/)?gist\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+$/i - if (path.search(exp1) === 0 || path.search(exp5) === 0 || !Config.cnpmjs && (path.search(exp3) === 0 || path.search(exp4) === 0)) { - return httpHandler(req, path) + const exp6 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/releases\/latest\/?$/i + if (path.search(exp6) === 0) { + return httpHandler(req, path, 'manual') + } + else if (path.search(exp1) === 0 || path.search(exp5) === 0 || !Config.cnpmjs && (path.search(exp3) === 0 || path.search(exp4) === 0)) { + return httpHandler(req, path, 'follow') } else if (path.search(exp2) === 0) { if (Config.jsdelivr){ const newUrl = path.replace('/blob/', '@').replace(/^(?:https?:\/\/)?github\.com/, 'https://cdn.jsdelivr.net/gh') return Response.redirect(newUrl, 302) }else{ path = path.replace('/blob/', '/raw/') - return httpHandler(req, path) + return httpHandler(req, path, 'follow') } } else if (path.search(exp3) === 0) { const newUrl = path.replace(/^(?:https?:\/\/)?github\.com/, 'https://github.com.cnpmjs.org') @@ -95,8 +99,9 @@ async function fetchHandler(e) { /** * @param {Request} req * @param {string} pathname + * @param {string} redirtype */ -function httpHandler(req, pathname) { +function httpHandler(req, pathname, redirtype) { const reqHdrRaw = req.headers // preflight @@ -120,7 +125,7 @@ function httpHandler(req, pathname) { const reqInit = { method: req.method, headers: reqHdrNew, - redirect: 'follow', + redirect: redirtype, body: req.body } return proxy(urlObj, reqInit, rawLen, 0)