Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 20 additions & 20 deletions lib/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.' })
Expand Down
1 change: 1 addition & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ export const config = {
'/api/stats/:path*',
'/api/og/:path*',
'/api/notify/:path*',
'/api/compare/:path*',
],
};
Loading