From f8081ef091a2b383dca19778c9959d7c80458cf7 Mon Sep 17 00:00:00 2001 From: Vansh Chaurasiya <114163734+vansh-codes@users.noreply.github.com> Date: Wed, 9 Oct 2024 20:42:41 +0530 Subject: [PATCH] Revert "Export and Api error resolved." --- .env.example | 3 +-- src/app/api/ai/route.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index c3ab036..ebfe2ec 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,7 @@ GITHUB_TOKEN=YOUR_GITHUB_TOKEN -GEMINI_KEY=YOUR_GEMINI_API_KEY # Steps to create: # 1. Go to Settings -> Developer settings -> Personal access tokens -> Tokens (classic) -> Generate new token -> Generate new token (classic) # 2. Permissions: repo, user # 3. Generate token # 4. Copy token -# 5. Paste token in .env.local +# 5. Paste token in .env.local \ No newline at end of file diff --git a/src/app/api/ai/route.js b/src/app/api/ai/route.js index 0e964cb..e6cc7da 100644 --- a/src/app/api/ai/route.js +++ b/src/app/api/ai/route.js @@ -1,9 +1,6 @@ import { NextResponse } from "next/server"; const GITHUB_API_URL = "https://api.github.com/graphql"; -// Declare contributions as an empty object globally -let contributions = {}; - export async function POST(req) { const { username } = await req.json(); @@ -61,14 +58,18 @@ export async function POST(req) { const data = await response.json(); console.log(data); if (data.data.user) { - contributions = data.data.user.contributionsCollection; // Assign contributions globally - return contributions; + const contributions = data.data.user.contributionsCollection; + return NextResponse.json({ + exists: true, + totalContributions: contributions.totalCommitContributions, + activeCodingDays: contributions.contributionCalendar.totalContributions + }); } else { - return null; + return NextResponse.json({ exists: false }); } } catch (error) { console.error("Error checking GitHub username:", error); return new NextResponse("Internal Server Error", { status: 500 }); } } -export { contributions }; +export default contributions;