Skip to content

feat: add public sponsors API for desktop app - #57

Merged
mkdir700 merged 1 commit into
mainfrom
feat/public-sponsors-api
Jun 30, 2026
Merged

feat: add public sponsors API for desktop app#57
mkdir700 merged 1 commit into
mainfrom
feat/public-sponsors-api

Conversation

@mkdir700

@mkdir700 mkdir700 commented Jun 30, 2026

Copy link
Copy Markdown
Member

What

Adds a public, unauthenticated GET /api/v1/sponsors endpoint that feeds the desktop app's About → Sponsors section. Mirrors the public sponsor wall on the site but is shaped for an external HTTP client.

Details

  • No auth, no admin-only fields — the desktop app holds no API token, and amountCents is never exposed.
  • Absolutised avatar paths — uploaded avatar paths (/api/sponsor-avatar/...) are resolved against the request origin so the desktop client can load them without knowing the site origin; already-absolute external URLs (e.g. GitHub CDN) are left untouched.
  • Wide-open CORS (*) — payload is public and read-only; the desktop webview fetches cross-origin. OPTIONS preflight handled.
  • Edge cachepublic, max-age=300, s-maxage=300 (5 min); sponsor changes are infrequent.
  • Reads through getPublicSponsors() from sponsors-store.

Response shape

{ "items": [{ "id", "name", "url", "since", "note", "avatar", "tier" }], "count": N }

Summary by CodeRabbit

  • New Features

    • Added a public sponsors API endpoint that returns a sponsor list with total count.
    • Sponsor avatars are now delivered as usable absolute URLs when needed.
  • Bug Fixes

    • Improved browser and third-party access to the sponsors feed with proper CORS support.
    • Added support for preflight requests so integrations can call the endpoint reliably.
  • Performance

    • Enabled short-term caching for faster responses and reduced load.

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
uc-website Error Error Jun 30, 2026 3:17pm

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new Next.js API route is added at src/app/api/v1/sponsors/route.ts. It exports a GET handler that fetches public sponsors, resolves relative avatar paths to absolute URLs, and returns JSON with 5-minute edge caching. An OPTIONS handler returns a 204 for CORS preflight. Both handlers include wide-open CORS headers.

Changes

Sponsors Public Feed Route

Layer / File(s) Summary
Route constants, OPTIONS, and GET handler
src/app/api/v1/sponsors/route.ts
Defines nodejs runtime, CORS and cache header constants, OPTIONS 204 preflight handler, and async GET handler that calls getPublicSponsors(), maps records to response objects with absolute avatar URLs, and returns NextResponse.json with items, count, CORS headers, and Cache-Control: max-age=300, s-maxage=300.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 A new route hops into the code,
Sponsors served on a public road,
Avatars made absolute and bright,
CORS wide open, cached just right,
Five minutes fresh, then fetch anew —
The rabbit ships this endpoint for you! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: a public sponsors API added for the desktop app.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/public-sponsors-api

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mkdir700
mkdir700 merged commit b27cb13 into main Jun 30, 2026
3 of 5 checks passed
@mkdir700
mkdir700 deleted the feat/public-sponsors-api branch June 30, 2026 15:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/api/v1/sponsors/route.ts`:
- Around line 37-47: The sponsors feed mapping in the GET handler can throw
because `new URL(s.avatar, origin)` is applied directly to every item, so a
single malformed `avatar` value from `sponsors-store.ts` can fail the whole
response. Update the `items` mapping in the sponsors route to resolve `avatar`
defensively per sponsor, catching invalid URL cases and falling back to the
original `s.avatar` value or `undefined` instead of throwing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e33d9758-d93c-4d1c-9dbc-e0edfb2bdf32

📥 Commits

Reviewing files that changed from the base of the PR and between 8fcb4a5 and 43ccb67.

📒 Files selected for processing (1)
  • src/app/api/v1/sponsors/route.ts

Comment on lines +37 to +47
const items = sponsors.map((s) => ({
id: s.id,
name: s.name,
url: s.url,
since: s.since,
note: s.note,
// Resolve relative avatar paths (uploaded avatars) to absolute URLs; leave
// already-absolute external URLs (e.g. GitHub CDN) untouched.
avatar: s.avatar ? new URL(s.avatar, origin).toString() : undefined,
tier: s.tier,
}));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

A single malformed avatar URL will 500 the entire feed.

new URL(s.avatar, origin) throws on an invalid input. Internal paths from resolveAvatar are always well-formed, but row.avatarUrl is an externally/admin-supplied value (per sponsors-store.ts); one bad entry would reject the whole GET and break the endpoint for all sponsors. Resolve defensively per-item and fall back to the raw value (or undefined).

🛡️ Proposed defensive resolution
+function toAbsoluteAvatar(avatar: string | undefined, origin: string): string | undefined {
+  if (!avatar) return undefined;
+  try {
+    return new URL(avatar, origin).toString();
+  } catch {
+    return undefined;
+  }
+}
+
 export async function GET(req: NextRequest) {
   const origin = req.nextUrl.origin;
   const sponsors = await getPublicSponsors();

   const items = sponsors.map((s) => ({
     id: s.id,
     name: s.name,
     url: s.url,
     since: s.since,
     note: s.note,
     // Resolve relative avatar paths (uploaded avatars) to absolute URLs; leave
     // already-absolute external URLs (e.g. GitHub CDN) untouched.
-    avatar: s.avatar ? new URL(s.avatar, origin).toString() : undefined,
+    avatar: toAbsoluteAvatar(s.avatar, origin),
     tier: s.tier,
   }));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const items = sponsors.map((s) => ({
id: s.id,
name: s.name,
url: s.url,
since: s.since,
note: s.note,
// Resolve relative avatar paths (uploaded avatars) to absolute URLs; leave
// already-absolute external URLs (e.g. GitHub CDN) untouched.
avatar: s.avatar ? new URL(s.avatar, origin).toString() : undefined,
tier: s.tier,
}));
function toAbsoluteAvatar(avatar: string | undefined, origin: string): string | undefined {
if (!avatar) return undefined;
try {
return new URL(avatar, origin).toString();
} catch {
return undefined;
}
}
export async function GET(req: NextRequest) {
const origin = req.nextUrl.origin;
const sponsors = await getPublicSponsors();
const items = sponsors.map((s) => ({
id: s.id,
name: s.name,
url: s.url,
since: s.since,
note: s.note,
// Resolve relative avatar paths (uploaded avatars) to absolute URLs; leave
// already-absolute external URLs (e.g. GitHub CDN) untouched.
avatar: toAbsoluteAvatar(s.avatar, origin),
tier: s.tier,
}));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/api/v1/sponsors/route.ts` around lines 37 - 47, The sponsors feed
mapping in the GET handler can throw because `new URL(s.avatar, origin)` is
applied directly to every item, so a single malformed `avatar` value from
`sponsors-store.ts` can fail the whole response. Update the `items` mapping in
the sponsors route to resolve `avatar` defensively per sponsor, catching invalid
URL cases and falling back to the original `s.avatar` value or `undefined`
instead of throwing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant