From 6d30820daa35da2eecfbcd561318e7e31c5cee19 Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Thu, 24 Jul 2025 20:04:21 +0800 Subject: [PATCH] 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. --- src/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 248b55f..ddc329e 100644 --- a/src/index.js +++ b/src/index.js @@ -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];