An empty `imageUrl=`, `logoUrl=` or `template=` returns an error instead of the default
維護者通常 1 天內回覆
@Saifjafri212213 已經在處理了。
開始於 2026年10月21日。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 88/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
研究方向
從src/lib/api-validation.ts開始,比較現有的width和height前處理與template、logoUrl和imageUrl的 schema。檢查tests/api/og.test.ts中的 schema 測試,接著檢查模擬 renderer 的路由測試。空值使用預設值、無效的非空 URL 仍回傳 400,且 schema 和路由測試涵蓋這些情況時,工作就算完成。
由索引模型根據 Issue 內容生成。
描述
/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.
- 主要語言
- TypeScript
- 星號
- 8
- 分支
- 4
- 平均合併
- 5 小時 19 分鐘
- 30 天內合併 PR
- 99
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codercops/ogcops 的其他 Issue
-
good first issue hacktoberfest templates
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
Add the Office Hours event template (`event-office-hours`)可能已有人在做 @bhushan4work 於 1 天前認領。 未關閉good first issue hacktoberfest templates
codercops/ogcops#237 · 2 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
good first issue hacktoberfest templates
難度 3/5 1-2 天 新手友好度 76/100
維護者通常 1 天內回覆
-
`npm run dev` keeps serving old images from `/api/og` after a template change可能已有人在做 @srujankaleru2007 於 1 天前認領。 未關閉bug good first issue hacktoberfest
codercops/ogcops#228 · 2 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Add the Top Episodes podcast template (`podcast-top-episodes`)可能已有人在做 @piyusshhjangid 於 1 天前認領。 未關閉good first issue hacktoberfest templates
codercops/ogcops#226 · 2 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
farion1231/cc-switch#8829 ·
維護者通常 1 天內回覆
-
[core-client] Remove unused hand-maintained transport helpers after the definition-table cutover未關閉doc-audit enhancement
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100