From dda048f5aa238c934e59e669589b1d6a12e1a7d8 Mon Sep 17 00:00:00 2001 From: Amlan Roy <59330872+amlan-roy@users.noreply.github.com> Date: Sat, 2 Mar 2024 13:24:19 +0530 Subject: [PATCH] 0.9.3 (#81) * minor fix (#75) * minor fix * fix * Bump undici and firebase (#74) Bumps [undici](https://github.com/nodejs/undici) to 5.28.3 and updates ancestor dependency [firebase](https://github.com/firebase/firebase-js-sdk). These dependencies need to be updated together. Updates `undici` from 5.26.5 to 5.28.3 - [Release notes](https://github.com/nodejs/undici/releases) - [Commits](https://github.com/nodejs/undici/compare/v5.26.5...v5.28.3) Updates `firebase` from 10.8.0 to 10.8.1 - [Release notes](https://github.com/firebase/firebase-js-sdk/releases) - [Changelog](https://github.com/firebase/firebase-js-sdk/blob/master/CHANGELOG.md) - [Commits](https://github.com/firebase/firebase-js-sdk/compare/firebase@10.8.0...firebase@10.8.1) --- updated-dependencies: - dependency-name: undici dependency-type: indirect - dependency-name: firebase dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amlan Roy <59330872+amlan-roy@users.noreply.github.com> * fix: fix bug in generate variant page (#79) * fix: remove unused code used for debugging (#80) --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- next.config.js | 4 ++-- src/app/(home-page)/home/page.tsx | 2 +- src/middleware.ts | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/next.config.js b/next.config.js index 767719f..658404a 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,4 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = {}; -module.exports = nextConfig +module.exports = nextConfig; diff --git a/src/app/(home-page)/home/page.tsx b/src/app/(home-page)/home/page.tsx index ea9313a..1554d1a 100644 --- a/src/app/(home-page)/home/page.tsx +++ b/src/app/(home-page)/home/page.tsx @@ -26,7 +26,7 @@ const page: React.FC = () => { - + diff --git a/src/middleware.ts b/src/middleware.ts index d60075d..5f79881 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -62,6 +62,13 @@ export async function middleware(req: NextRequest) { return NextResponse.redirect(new URL("/generate-resume/base", req.url)); } + if (req.nextUrl.pathname.endsWith("/generate-resume/variant")) { + const randomFormId = getUniqueHashId(8); + return NextResponse.redirect( + new URL(`/generate-resume/${randomFormId}`, req.url) + ); + } + if (req.nextUrl.pathname.endsWith("/enter-data")) { if (!req.nextUrl.searchParams.get("id")) { // redirect to '/enter-data' route with all the params passed to the request, and for id query param, add/replace it with id = base @@ -73,3 +80,19 @@ export async function middleware(req: NextRequest) { } return res; } + +/** + * Generates a unique hash id with the given length. Minimum length is 8. + * Use the additional length to add more characters to the hash id. + * + * @param additionalLength - The additional length to be added to the hash id. + * @returns A unique hash id. + */ +export function getUniqueHashId(additionalLength: number): string { + const idChars: string = "ABCDEFGHJKMNPQRSTUVWXYZ"; + const now: Date = new Date(); + let id = now.getTime().toString().slice(-8); + for (let i = 0; i < additionalLength; i++) + id += idChars[Math.floor(Math.random() * idChars.length)]; + return id; +}