File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,10 +21,24 @@ async function handleRequest(request) {
2121 }
2222
2323 if ( pathname . startsWith ( "/pool" ) ) {
24- const packageName = pathArray . at ( - 1 ) ;
25- const packageNameModified = packageName . replaceAll ( / [ ^ a - z A - Z 0 - 9 - _ + % ] + / g, "." ) ;
26- return Response . redirect (
27- "https://github.com/termux-user-repository/dists/releases/download/0.1/" + packageNameModified , 302 ) ;
24+ const packageDebName = pathArray . at ( - 1 ) ;
25+ const packageDebNameModified = packageDebName . replaceAll ( / [ ^ a - z A - Z 0 - 9 - _ + % ] + / g, "." ) ;
26+ const fallbackUrl = "https://github.com/termux-user-repository/dists/releases/download/0.1/" + packageDebNameModified ;
27+ try {
28+ // Try the new package_name tag
29+ const packageName = packageDebName . split ( "_" ) . at ( 0 ) ;
30+ const primaryUrl = "https://github.com/termux-user-repository/dists/releases/download/" + packageName + "/" + packageDebNameModified ;
31+ const response = await fetch ( primaryUrl , { method : "HEAD" } ) ;
32+ if ( response . ok ) {
33+ return Response . redirect ( primaryUrl , 302 ) ;
34+ } else {
35+ // Fallback to legacy 0.1 tag
36+ return Response . redirect ( fallbackUrl , 302 ) ;
37+ }
38+ } catch ( err ) {
39+ // Fallback to legacy 0.1 tag
40+ return Response . redirect ( fallbackUrl , 302 ) ;
41+ }
2842 }
2943
3044 return Response . redirect ( "https://github.com/termux-user-repository/tur" , 302 ) ;
You can’t perform that action at this time.
0 commit comments