diff --git a/src/app/api/ai/route.js b/src/app/api/ai/route.js
new file mode 100644
index 0000000..e6cc7da
--- /dev/null
+++ b/src/app/api/ai/route.js
@@ -0,0 +1,75 @@
+import { NextResponse } from "next/server";
+const GITHUB_API_URL = "https://api.github.com/graphql";
+
+export async function POST(req) {
+ const { username } = await req.json();
+
+ if (!username) {
+ return new NextResponse("Username required", { status: 400 });
+ }
+
+ const query = `
+ query ($login: String!) {
+ user(login: $login) {
+ login
+ contributionsCollection {
+ totalCommitContributions
+ contributionCalendar {
+ totalContributions
+ }
+ pullRequestContributionsByRepository {
+ repository {
+ name
+ }
+ totalCount
+ }
+ }
+ repositories(first: 100, orderBy: {field: STARGAZERS, direction: DESC}) {
+ nodes {
+ primaryLanguage {
+ name
+ }
+ }
+ }
+ }
+ }
+ `;
+
+ try {
+ const response = await fetch(GITHUB_API_URL, {
+ method: "POST",
+ headers: {
+ Accept: "application/json",
+ Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ query,
+ variables: { login: username },
+ }),
+ });
+
+ if (!response.ok) {
+ return new NextResponse(await response.text(), {
+ status: response.status,
+ });
+ }
+
+ const data = await response.json();
+ console.log(data);
+ if (data.data.user) {
+ const contributions = data.data.user.contributionsCollection;
+ return NextResponse.json({
+ exists: true,
+ totalContributions: contributions.totalCommitContributions,
+ activeCodingDays: contributions.contributionCalendar.totalContributions
+ });
+ } else {
+ return NextResponse.json({ exists: false });
+ }
+ } catch (error) {
+ console.error("Error checking GitHub username:", error);
+ return new NextResponse("Internal Server Error", { status: 500 });
+ }
+}
+export default contributions;
diff --git a/src/app/api/user/route.js b/src/app/api/user/route.js
index e37e2f8..147a78c 100644
--- a/src/app/api/user/route.js
+++ b/src/app/api/user/route.js
@@ -1,5 +1,4 @@
import { NextResponse } from "next/server";
-import { generateUserTagline } from "../../../../ai/generateTagline";
const GITHUB_API_URL = "https://api.github.com/graphql";
@@ -14,25 +13,6 @@ export async function POST(req) {
query ($login: String!) {
user(login: $login) {
login
- contributionsCollection {
- totalCommitContributions
- contributionCalendar {
- totalContributions
- }
- pullRequestContributionsByRepository {
- repository {
- name
- }
- totalCount
- }
- }
- repositories(first: 100, orderBy: {field: STARGAZERS, direction: DESC}) {
- nodes {
- primaryLanguage {
- name
- }
- }
- }
}
}
`;
@@ -60,14 +40,7 @@ export async function POST(req) {
const data = await response.json();
console.log(data);
if (data.data.user) {
- const contributions = data.data.user.contributionsCollection;
- const tagline = await generateUserTagline(username, contributions);
- return NextResponse.json({
- exists: true,
- totalContributions: contributions.totalCommitContributions,
- activeCodingDays: contributions.contributionCalendar.totalContributions,
- tagline,
- });
+ return NextResponse.json({ exists: true });
} else {
return NextResponse.json({ exists: false });
}