Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#166 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Saifjafri212213 đang làm issue này rồi.

Từ ngày 21/10/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu trong src/lib/api-validation.ts bằng cách so sánh bước tiền xử lý hiện có của width và height với các schema của template, logoUrl và imageUrl. Kiểm tra các bài kiểm thử schema trong tests/api/og.test.ts, sau đó là các bài kiểm thử route mô phỏng renderer. Công việc hoàn tất khi các giá trị rỗng dùng giá trị mặc định, URL không rỗng nhưng không hợp lệ vẫn trả về 400, và các bài kiểm thử schema cùng route bao quát những trường hợp đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
8
Fork
4
Merge trung bình
6 giờ 9 phút
Pull request đã merge (30 ngày)
66

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của codercops/ogcops

Tất cả issue của codercops/ogcops

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.