diff --git a/lib/validations.ts b/lib/validations.ts index faa64cb7..13e00e5f 100644 --- a/lib/validations.ts +++ b/lib/validations.ts @@ -322,6 +322,26 @@ export const githubParamsSchema = z.object({ refresh: z.string().optional().transform(toRefreshFlag), }); +export const compareParamsSchema = z + .object({ + user1: z + .string({ error: 'Missing "user1" parameter' }) + .trim() + .min(1, { message: 'user1 is required' }) + .max(39, { message: 'GitHub username cannot exceed 39 characters' }) + .regex(GITHUB_USERNAME_REGEX, { message: 'Invalid GitHub username for user1' }), + user2: z + .string({ error: 'Missing "user2" parameter' }) + .trim() + .min(1, { message: 'user2 is required' }) + .max(39, { message: 'GitHub username cannot exceed 39 characters' }) + .regex(GITHUB_USERNAME_REGEX, { message: 'Invalid GitHub username for user2' }), + }) + .refine((data) => data.user1.toLowerCase() !== data.user2.toLowerCase(), { + message: 'Cannot compare a user with themselves.', + path: ['user2'], + }); + export const ogParamsSchema = z .object({ user: z.string().trim().optional().transform(toEmptyStringAsUndefined), @@ -453,26 +473,6 @@ export const wrappedParamsSchema = z.object({ height: dimensionParam('height', 80, 800), }); -export const compareParamsSchema = z - .object({ - user1: z - .string({ error: 'Missing user1 parameter' }) - .trim() - .min(1, { message: 'user1 is required' }) - .max(39, { message: 'GitHub username cannot exceed 39 characters' }) - .regex(GITHUB_USERNAME_REGEX, { message: 'Invalid GitHub username for user1' }), - user2: z - .string({ error: 'Missing user2 parameter' }) - .trim() - .min(1, { message: 'user2 is required' }) - .max(39, { message: 'GitHub username cannot exceed 39 characters' }) - .regex(GITHUB_USERNAME_REGEX, { message: 'Invalid GitHub username for user2' }), - }) - .refine((data) => data.user1.toLowerCase() !== data.user2.toLowerCase(), { - message: 'Cannot compare a user with themselves.', - path: ['user2'], - }); - export const notifyPostSchema = z.object({ username: z .string({ error: 'Username is required.' }) diff --git a/middleware.ts b/middleware.ts index bbb09744..981916e4 100644 --- a/middleware.ts +++ b/middleware.ts @@ -62,5 +62,6 @@ export const config = { '/api/stats/:path*', '/api/og/:path*', '/api/notify/:path*', + '/api/compare/:path*', ], };