fix: raw.github.com在cnpmjs为1下的错误302

pull/49/head
hunsh 2021-11-10 12:15:23 +08:00
parent 4d655d09b7
commit d978d13efb
2 changed files with 3 additions and 2 deletions

View File

@ -140,7 +140,8 @@ def proxy(u):
return redirect(u)
elif (jsdelivr or pass_by) and exp4.match(u):
u = re.sub(r'(\.com/.*?/.+?)/(.+?/)', r'\1@\2', u, 1)
u = u.replace('raw.githubusercontent.com', 'cdn.jsdelivr.net/gh', 1)
_u = u.replace('raw.githubusercontent.com', 'cdn.jsdelivr.net/gh', 1)
u = u.replace('raw.github.com', 'cdn.jsdelivr.net/gh', 1) if _u == u else _u
return redirect(u)
else:
if exp2.match(u):

View File

@ -84,7 +84,7 @@ async function fetchHandler(e) {
const newUrl = path.replace(/^(?:https?:\/\/)?github\.com/, 'https://github.com.cnpmjs.org')
return Response.redirect(newUrl, 302)
} else if (path.search(exp4) === 0) {
const newUrl = path.replace(/(?<=com\/.+?\/.+?)\/(.+?\/)/, '@$1').replace(/^(?:https?:\/\/)?raw\.githubusercontent\.com/, 'https://cdn.jsdelivr.net/gh')
const newUrl = path.replace(/(?<=com\/.+?\/.+?)\/(.+?\/)/, '@$1').replace(/^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com/, 'https://cdn.jsdelivr.net/gh')
return Response.redirect(newUrl, 302)
} else {
return fetch(ASSET_URL + path)