Add transformPath utility to handle platform prefixes
Introduces the transformPath function to remove platform-specific prefixes from paths. This utility helps standardize path handling by stripping prefixes like /gh/ or /cr/docker/ based on the platform key.
This commit is contained in:
1 parent
9ea2bd0cfc
commit
24a53398fb
1 file changed
+19
@@ -594,6 +594,24 @@ function parseAuthenticate(authenticateStr) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the effective path by removing the platform prefix.
|
||||
*
|
||||
* @param {string} path - The original path (e.g. /gh/user/repo, /cr/docker/image)
|
||||
* @param {string} platform - The platform key (e.g. gh, cr-docker)
|
||||
* @returns {string} The transformed path (e.g. /user/repo, /image)
|
||||
*/
|
||||
function transformPath(path, platform) {
|
||||
// Convert platform key to path prefix format (e.g. cr-docker -> /cr/docker/)
|
||||
const platformPrefix = `/${platform.replace(/-/g, '/')}/`;
|
||||
|
||||
if (path.startsWith(platformPrefix)) {
|
||||
return path.substring(platformPrefix.length - 1); // Keep the leading slash
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches authentication token from container registry token service.
|
||||
*
|
||||
@@ -1223,6 +1241,7 @@ async function handleRequest(request, env, ctx) {
|
||||
|
||||
// Try to get a token for public access (without authorization)
|
||||
const tokenResponse = await fetchToken(wwwAuthenticate, scope || '', '');
|
||||
|
||||
if (tokenResponse.ok) {
|
||||
const tokenData = await tokenResponse.json();
|
||||
if (tokenData.token) {
|
||||
|
||||
Reference in new issue
Block a user