Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make redirects work as intended #52

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,56 @@ export function mapUrlPathToBucketPath(
let bucketPath: string | undefined;

const splitPath = url.pathname.split('/'); // ['', 'docs', 'asd', '123']
console.log(' splitPath: ' + splitPath)
const basePath = splitPath[1]; // 'docs'

if (
REDIRECT_MAP.has(`${DOWNLOAD_PATH_PREFIX}/${splitPath[1]}/${splitPath[2]}`)
) {
// All items in REDIRECT_MAP are three levels deep, that is asserted in tests
bucketPath = `${REDIRECT_MAP.get(
`${DOWNLOAD_PATH_PREFIX}/${splitPath[1]}/${splitPath[2]}`
)}/${splitPath.slice(3).join('/')}`;
} else if (basePath in urlToBucketPathMap) {
if (basePath in urlToBucketPathMap) {
bucketPath = urlToBucketPathMap[basePath];
console.log(' initial bucket path: ' + bucketPath)

// This works and handles child paths, but we're splitting it again.
// nodejs/release/latest-v20.x
const bucketPathSplit = bucketPath.split('/'); // ['nodejs', 'release', 'latest-v20.x', '']

// Path we check for if it's redirected
// 'nodejs/release/latest-v20.x'
const redirectablePath = `${bucketPathSplit[0]}/${bucketPathSplit[1]}${bucketPathSplit.length >= 3 ? `/${bucketPathSplit[2]}` : ''}`;
console.log(' redirectablePath: ' + redirectablePath)

if (REDIRECT_MAP.has(redirectablePath)) {
bucketPath = REDIRECT_MAP.get(redirectablePath) + '/' + bucketPath.substring(redirectablePath.length + 1);
console.log(' redirected: ' + bucketPath);
}

console.log(' final bucket path: ' + bucketPath)
} else if (env.DIRECTORY_LISTING !== 'restricted') {
bucketPath = url.pathname.substring(1);
}

// original
// if (basePath in urlToBucketPathMap) {
// const bucketPathParts = urlToBucketPathMap[basePath];
// console.log(' initial bucket path: ' + bucketPath)

// // TODO: have urlToBucketPathMap return an array of this so we don't need to split it
// // nodejs/release/latest-v20.x
// const bucketPathSplit = bucketPath.split('/'); // ['nodejs', 'release', 'latest-v20.x', ...]

// // Path we check for if it's redirected
// // 'nodejs/release/latest-v20.x'
// const redirectablePath = `${bucketPathSplit[0]}/${bucketPathSplit[1]}${bucketPathSplit.length >= 3 ? `/${bucketPathSplit[2]}` : ''}`;
// console.log(' redirectablePath: ' + redirectablePath)

// if (REDIRECT_MAP.has(redirectablePath)) {
// bucketPath = REDIRECT_MAP.get(redirectablePath) + '/' + bucketPath.substring(redirectablePath.length + 1);
// console.log(' redirected: ' + bucketPath);
// }

// console.log(' final bucket path: ' + bucketPath)
// } else if (env.DIRECTORY_LISTING !== 'restricted') {
// bucketPath = url.pathname.substring(1);
// }

return bucketPath !== undefined ? decodeURIComponent(bucketPath) : undefined;
}

Expand Down
Loading