Skip to content
Closed
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
6 changes: 3 additions & 3 deletions app/api/streak/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ export async function GET(request: Request) {
theme: themeName,
bg: isAutoTheme ? selectedTheme.bg : bg || selectedTheme.bg,
bgType,
bgStart,
bgEnd,
bgStart: bgStart ?? selectedTheme.bg,
bgEnd: bgEnd ?? selectedTheme.bg,
bgAngle,
text: isAutoTheme ? selectedTheme.text : text || selectedTheme.text,
accent: isAutoTheme ? selectedTheme.accent : accent || selectedTheme.accent,
border,
border: border ?? selectedTheme.accent,
radius,
speed: validatedSpeed,
scale,
Expand Down
48 changes: 22 additions & 26 deletions lib/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,8 @@ const baseStreakParamsSchema = z.object({
return normalized;
}
const matchedKey = Object.keys(themes).find((key) => key.toLowerCase() === normalized);
return matchedKey || val;
return matchedKey || 'dark';
})
.refine(
(val) => {
return val === 'auto' || val === 'random' || Object.hasOwn(themes, val);
},
{
message: `Invalid theme. Supported themes: ${['auto', 'random', ...Object.keys(themes)].join(', ')}`,
}
)
.default('dark'),
bg: z
.string()
Expand All @@ -234,17 +226,25 @@ const baseStreakParamsSchema = z.object({
bgStart: z
.string()
.optional()
.refine((val) => !val || /^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6,8}$/.test(val.replace('#', '')), {
message: 'bgStart must be a valid hex color',
})
.transform((val) => (val ? sanitizeHexColor(val, '0d1117') : undefined)),
.transform((val) => {
if (!val) return undefined;
const cleanVal = val.replace(/^#/, '');
if (/^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6,8}$/.test(cleanVal)) {
return sanitizeHexColor(val, '0d1117');
}
return undefined;
}),
bgEnd: z
.string()
.optional()
.refine((val) => !val || /^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6,8}$/.test(val.replace('#', '')), {
message: 'bgEnd must be a valid hex color',
})
.transform((val) => (val ? sanitizeHexColor(val, '0d1117') : undefined)),
.transform((val) => {
if (!val) return undefined;
const cleanVal = val.replace(/^#/, '');
if (/^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6,8}$/.test(cleanVal)) {
return sanitizeHexColor(val, '0d1117');
}
return undefined;
}),
bgAngle: z
.string()
.optional()
Expand Down Expand Up @@ -507,17 +507,13 @@ const baseStreakParamsSchema = z.object({
border: z
.string()
.optional()
.refine(
(val) => {
if (val === undefined || val === '') return true;
const cleanVal = val.replace(/^#/, '');
return /^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6,8}$/.test(cleanVal);
},
{ message: 'border must be a valid hex color (with or without #)' }
)
.transform((val) => {
if (!val) return undefined;
return sanitizeHexColor(val, '58a6ff');
const cleanVal = val.replace(/^#/, '');
if (/^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6,8}$/.test(cleanVal)) {
return sanitizeHexColor(val, '58a6ff');
}
return undefined;
}),
});

Expand Down
Loading