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
- 平均合并
- 6 小时 9 分钟
- 30 天内合并 PR
- 66
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
codercops/ogcops 的其他 Issue
-
accessibility bug good first issue hacktoberfest ui
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
accessibility bug good first issue hacktoberfest
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
bug good first issue hacktoberfest ui
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
bug good first issue hacktoberfest
难度 2/5 1-3 小时 新手友好度 88/100
codercops/ogcops#167 · 1 条评论 ·
维护者通常 1 天内回复
-
bug good first issue hacktoberfest
难度 2/5 1-3 小时 新手友好度 87/100
codercops/ogcops#164 · 2 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
maniator/verticopolis#1303 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
components-web-app/docs#297 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
appwrite/mcp-for-docs#23 · 1 条评论 ·
-
`@vanilla-extract/turbopack-plugin`: "getImageSize is not a function" with Next.js 16.4.x when a `.css.ts` file imports an image可能已有人在做 @aevarOrigo 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
vanilla-extract-css/vanilla-extract#1799 · 1 条评论 ·
-
native
难度 2/5 1-3 小时 新手友好度 72/100
prime-radiant-inc/evener#4839 ·
维护者通常 1 天内回复