Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

An empty `imageUrl=`, `logoUrl=` or `template=` returns an error instead of the default

已關閉 適合新手
#166 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@Saifjafri212213 已經在處理了。

開始於 2026年10月21日。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
88/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
api, backend

研究方向

從src/lib/api-validation.ts開始,比較現有的width和height前處理與template、logoUrl和imageUrl的 schema。檢查tests/api/og.test.ts中的 schema 測試,接著檢查模擬 renderer 的路由測試。空值使用預設值、無效的非空 URL 仍回傳 400,且 schema 和路由測試涵蓋這些情況時,工作就算完成。

由索引模型根據 Issue 內容生成。

描述

bug good first issue hacktoberfest

/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:

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.preprocess for logoUrl, imageUrl and template, so an empty value counts as missing. template= then gets blog-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), logoUrl and imageUrl (lines 14 and 15), and the width/height preprocess (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= renders blog-minimal-dark
  • imageUrl=not-a-url still returns 400
  • Tests for the schema and for the route
  • npm run check, npm run test and npm run build pass

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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

codercops/ogcops 的其他 Issue

查看 codercops/ogcops 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。