Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions src/app/api/public/[username]/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { getUserByUsername } from "@/lib/supabase";
import {
fetchPublicTopRepos,
fetchPublicContributions,
fetchPublicStreak,
} from "@/lib/public-profile-data";
import { fetchPublicProfile } from "@/lib/public-profile-data";
import { getUpstashConfig, upstashRateLimitFixedWindow } from "@/lib/upstash-rest";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -92,31 +87,14 @@ export async function GET(
);
}

// Look up user in Supabase
const user = await getUserByUsername(username);
const profile = await fetchPublicProfile(username);

if (!user) {
if (!profile) {
return NextResponse.json(
{ error: "User not found or profile is not public" },
{ status: 404 }
);
}

// Use GITHUB_TOKEN env var if available for higher rate limits
const githubToken = process.env.GITHUB_TOKEN;

// Fetch all metrics in parallel
const [repos, contributions, streak] = await Promise.all([
fetchPublicTopRepos(user.github_login, githubToken, 30),
fetchPublicContributions(user.github_login, githubToken, 30),
fetchPublicStreak(user.github_login, githubToken),
]);

return NextResponse.json({
username: user.github_login,
userId: user.id,
repos,
contributions,
streak,
});
return NextResponse.json(profile);
}
Loading
Loading