@@ -36,7 +36,7 @@ const PREFLIGHT_INIT = {
3636 */
3737function makeRes ( body , status = 200 , headers = { } ) {
3838 headers [ 'access-control-allow-origin' ] = '*'
39- return new Response ( body , { status, headers} )
39+ return new Response ( body , { status, headers } )
4040}
4141
4242
@@ -77,13 +77,14 @@ async function fetchHandler(e) {
7777 const exp3 = / ^ (?: h t t p s ? : \/ \/ ) ? g i t h u b \. c o m \/ .+ ?\/ .+ ?\/ (?: i n f o | g i t - ) .* $ / i
7878 const exp4 = / ^ (?: h t t p s ? : \/ \/ ) ? r a w \. g i t h u b u s e r c o n t e n t \. c o m \/ .+ ?\/ .+ ?\/ .+ ?\/ .+ $ / i
7979 const exp5 = / ^ (?: h t t p s ? : \/ \/ ) ? g i s t \. (?: g i t h u b u s e r c o n t e n t | g i t h u b ) \. c o m \/ .+ ?\/ .+ ?\/ .+ $ / i
80+ const exp6 = / ^ (?: h t t p s ? : \/ \/ ) .+ ?\. g i t h u b \. c o m \/ + $ / i
8081 if ( path . search ( exp1 ) === 0 || path . search ( exp5 ) === 0 || ! Config . cnpmjs && ( path . search ( exp3 ) === 0 || path . search ( exp4 ) === 0 ) ) {
8182 return httpHandler ( req , path )
8283 } else if ( path . search ( exp2 ) === 0 ) {
83- if ( Config . jsdelivr ) {
84+ if ( Config . jsdelivr ) {
8485 const newUrl = path . replace ( '/blob/' , '@' ) . replace ( / ^ (?: h t t p s ? : \/ \/ ) ? g i t h u b \. c o m / , 'https://cdn.jsdelivr.net/gh' )
8586 return Response . redirect ( newUrl , 302 )
86- } else {
87+ } else {
8788 path = path . replace ( '/blob/' , '/raw/' )
8889 return httpHandler ( req , path )
8990 }
@@ -93,7 +94,10 @@ async function fetchHandler(e) {
9394 } else if ( path . search ( exp4 ) === 0 ) {
9495 const newUrl = path . replace ( / (?< = c o m \/ .+ ?\/ .+ ?) \/ ( .+ ?\/ ) / , '@$1' ) . replace ( / ^ (?: h t t p s ? : \/ \/ ) ? r a w \. g i t h u b u s e r c o n t e n t \. c o m / , 'https://cdn.jsdelivr.net/gh' )
9596 return Response . redirect ( newUrl , 302 )
96- } else {
97+ } else if ( path . search ( exp6 ) === 0 ) {
98+ return httpHandler ( req , path )
99+ }
100+ else {
97101 return fetch ( ASSET_URL + path )
98102 }
99103}
0 commit comments