Prioritize specific platform paths in detection logic

Platforms are now sorted by path length in descending order before matching, ensuring that more specific paths (e.g., conda/community) are matched before general ones (e.g., conda). This prevents incorrect platform detection when similar prefixes exist.
This commit is contained in:
xixu-me committed 2025-07-24 20:04:21 +08:00
1 parent dc40cacf81
commit 6d30820daa
1 file changed
+9 -1
+9 -1
View File
@@ -150,8 +150,16 @@ async function handleRequest(request, env, ctx) {
let platform;
// Platform detection using transform patterns
// Sort platforms by path length (descending) to prioritize more specific paths
// e.g., conda/community should match before conda, pypi/files before pypi
const sortedPlatforms = Object.keys(CONFIG.PLATFORMS).sort((a, b) => {
const pathA = `/${a.replace("-", "/")}/`;
const pathB = `/${b.replace("-", "/")}/`;
return pathB.length - pathA.length;
});
platform =
Object.keys(CONFIG.PLATFORMS).find((key) => {
sortedPlatforms.find((key) => {
const expectedPrefix = `/${key.replace("-", "/")}/`;
return url.pathname.startsWith(expectedPrefix);
}) || url.pathname.split("/")[1];