An empty `imageUrl=`, `logoUrl=` or `template=` returns an error instead of the default
Maintainer antworten meist innerhalb von 1 Tag
@Saifjafri212213 arbeitet bereits daran.
Seit 21.10.2026.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 88/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- typescript
Rechercherichtung
Beginne in src/lib/api-validation.ts mit dem Vergleich der bestehenden Vorverarbeitung von width und height mit den Schemas für template, logoUrl und imageUrl. Prüfe die Schema-Tests in tests/api/og.test.ts und anschließend die Routentests, die den Renderer mocken. Fertig ist es, wenn leere Werte Standardwerte verwenden, ungültige nichtleere URLs weiterhin 400 zurückgeben und die Schema- und Routentests diese Fälle abdecken.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
/api/og treats an empty parameter as "use the default": title= or bgColor= with nothing after them still give the normal image. Three parameters don't:
- https://og.codercops.com/api/og?template=blog-photo-overlay&imageUrl= returns 400
{"error":"imageUrl: Invalid url"}. WithoutimageUrl=, the same template renders with its gradient background. logoUrl=returns 400{"error":"logoUrl: Invalid url"}with any template, for example https://og.codercops.com/api/og?template=blog-minimal-dark&logoUrl= (no template readslogoUrlyet, but the schema still checks it).- https://og.codercops.com/api/og?template= returns 404
{"error":"Template \"\" not found"}. The API docs say the default template isblog-minimal-dark(src/pages/api-docs.astro, line 68), and that's what you get whentemplateis left out.
This is easy to hit when the URL is built from CMS data, like imageUrl={{ post.cover }} on a post without a cover image: the whole OG image fails instead of falling back.
In src/lib/api-validation.ts, logoUrl and imageUrl (lines 14 and 15) are z.string().url().optional(). .optional() only covers a missing key, so an empty string goes on to .url() and fails. template (line 4) uses .default('blog-minimal-dark'), which also only applies when the key is missing. width and height (lines 16 to 23) already handle this: z.preprocess turns '' into undefined before the rest of the check.
What to do
- Use the same
z.preprocessforlogoUrl,imageUrlandtemplate, so an empty value counts as missing.template=then getsblog-minimal-dark, and the two URLs fall back to the template's defaults. - A value that's there but isn't a URL, like
imageUrl=not-a-url, should still return 400.
Where to look
src/lib/api-validation.ts:template(line 4),logoUrlandimageUrl(lines 14 and 15), and thewidth/heightpreprocess (lines 16 to 23)src/pages/api/og.ts: the 400 for invalid params (lines 41 to 47) and the 404 for an unknown template (lines 61 to 70)tests/api/og.test.ts: the schema tests (line 11) and the route tests, which mock the renderer (from line 269)
Acceptance criteria
-
?template=blog-photo-overlay&imageUrl=and?logoUrl=return the same image as leaving the parameter out -
?template=rendersblog-minimal-dark -
imageUrl=not-a-urlstill returns 400 - Tests for the schema and for the route
-
npm run check,npm run testandnpm run buildpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #166 in the description.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 8
- Forks
- 4
- Ø Merge
- 5 Std. 44 Min.
- Gemergte PRs (30 T.)
- 83
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus codercops/ogcops
-
Add the Order Status e-commerce template (`ecommerce-order-status`)Evtl. vergeben @piyusshhjangid hat das heute übernommen. Offengood first issue hacktoberfest templates
codercops/ogcops#181 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add the Cheat Sheet tutorial template (`tutorial-cheat-sheet`)Evtl. vergeben @srikar-naidu hat das heute übernommen. Offenhacktoberfest help wanted templates
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 45/100
codercops/ogcops#180 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add the Call for Speakers event template (`event-call-for-speakers`)Evtl. vergeben @Saifjafri212213 hat das heute übernommen. Offengood first issue hacktoberfest templates
codercops/ogcops#177 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add the Day Streak developer template (`developer-day-streak`)Evtl. vergeben @srikar-naidu hat das heute übernommen. Offenhacktoberfest help wanted templates
codercops/ogcops#176 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
hacktoberfest
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 35/100
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in codercops/ogcops
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
db-ux-design-system/core-web#8613 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
foxglove/mcap#1907 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug internal-plugin pr-welcome upstream
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
dsh-tauri-desk/deepseek-harness-desktop#1225 · 1 Kommentar ·
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
unjs/unhead#1027 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag