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
平均合并
6 小时 9 分钟
30 天内合并 PR
66

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codercops/ogcops 的其他 Issue

查看 codercops/ogcops 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。