Skip to content

Commit 162f198

Browse files
authored
fix(api): pass gradient_stops and gradient_dir through validation and… (JhaSourav07#2244)
## Description Fixes JhaSourav07#2238 Custom gradient colors passed via `gradient_stops` and `gradient_dir` URL parameters were silently ignored, causing the badge to always render with the default blue gradient. This PR fixes the issue by: - Adding `gradient_stops` and `gradient_dir` to `streakParamsSchema` in `lib/validations.ts`, preventing them from being stripped during Zod validation. - Destructuring both fields from `parseResult.data` and passing them into the `BadgeParams` object in `app/api/streak/route.ts`. - Calling `generateCustomGradients(params)` before `renderTowers()` in `lib/svg/generator.ts` so `params.__customGradientId` is populated before tower rendering begins. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [X] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="1614" height="1007" alt="image" src="https://github.com/user-attachments/assets/3db5ed79-2b78-4d94-83a7-6ab65dcd20bb" /> ## Checklist before requesting a review: - [X] I have read the `CONTRIBUTING.md` file. - [X] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [X] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [X] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [X] I have started the repo. - [X] I have made sure that i have only one commit to merge in this PR. - [X] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [X] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents b081d07 + e2dcf0b commit 162f198

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

app/api/streak/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export async function GET(request: Request) {
9191
versus,
9292
shading,
9393
gradient,
94+
gradient_stops,
95+
gradient_dir,
9496
opacity,
9597
tz: tzParam,
9698
disable_particles,
@@ -173,6 +175,8 @@ export async function GET(request: Request) {
173175
versus,
174176
shading,
175177
gradient,
178+
gradient_stops,
179+
gradient_dir,
176180
opacity,
177181
disable_particles,
178182
glow,

lib/svg/generator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,9 @@ export function generateSVG(
646646
computeTowers(calendar, params.scale, stats.todayDate, params.mode),
647647
sf
648648
);
649+
if (params.gradient) {
650+
generateCustomGradients(params);
651+
}
649652
const towers = renderTowers(
650653
towerData,
651654
params,

lib/validations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ const baseStreakParamsSchema = z.object({
308308
return val === 'true';
309309
})
310310
.default(false),
311+
gradient_stops: z.string().optional(),
312+
gradient_dir: z.enum(['vertical', 'horizontal', 'diagonal']).catch('vertical').optional(),
311313
disable_particles: z
312314
.string()
313315
.optional()

0 commit comments

Comments
 (0)