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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
/.env
/devclans-local.pem
# dependencies
/node_modules
/.pnp
Expand Down
79 changes: 58 additions & 21 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,60 @@
{
"accessibility.alert.format": "never",
"accessibility.alert.save": "never",
"audioCues.volume": 0,
"audioCues.debouncePositionChanges": false,
"audioCues.diffLineDeleted": "off",
"audioCues.diffLineInserted": "off",
"audioCues.terminalQuickFix": "off",
"audioCues.terminalCommandFailed": "off",
"audioCues.taskFailed": "off",
"audioCues.taskCompleted": "off",
"audioCues.onDebugBreak": "off",
"audioCues.notebookCellFailed": "off",
"audioCues.notebookCellCompleted": "off",
"audioCues.noInlayHints": "off",
"audioCues.lineHasInlineSuggestion": "off",
"audioCues.lineHasFoldedArea": "off",
"audioCues.lineHasError": "off",
"audioCues.lineHasBreakpoint": "off",
"audioCues.diffLineModified": "off",
"audioCues.chatResponsePending": "off",
"editor.accessibilitySupport": "off"
"editor.accessibilitySupport": "off",
"accessibility.signals.sounds.volume": 0,
"accessibility.signals.debouncePositionChanges": false,
"accessibility.signals.lineHasError": {
"sound": "off"
},
"accessibility.signals.lineHasFoldedArea": {
"sound": "off"
},
"accessibility.signals.lineHasBreakpoint": {
"sound": "off"
},
"accessibility.signals.lineHasInlineSuggestion": {
"sound": "off"
},
"accessibility.signals.terminalQuickFix": {
"sound": "off"
},
"accessibility.signals.onDebugBreak": {
"sound": "off"
},
"accessibility.signals.noInlayHints": {
"sound": "off"
},
"accessibility.signals.taskCompleted": {
"sound": "off"
},
"accessibility.signals.taskFailed": {
"sound": "off"
},
"accessibility.signals.terminalCommandFailed": {
"sound": "off"
},
"accessibility.signals.notebookCellCompleted": {
"sound": "off"
},
"accessibility.signals.notebookCellFailed": {
"sound": "off"
},
"accessibility.signals.diffLineInserted": {
"sound": "off"
},
"accessibility.signals.diffLineDeleted": {
"sound": "off"
},
"accessibility.signals.diffLineModified": {
"sound": "off"
},
"accessibility.signals.chatResponsePending": {
"sound": "off"
},
"accessibility.signals.save": {
"announcement": "never"
},
"accessibility.signals.format": {
"announcement": "never"
},
"CodeGPT.apiKey": "Mistral"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"axios": "^1.6.5",
"bson": "^6.2.0",
"fast-json-stable-stringify": "^2.1.0",
"fs": "0.0.1-security",
"github-calendar": "^2.3.2",
"github-calendar-graph": "^0.2.8",
"ioredis": "^5.3.2",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions public/config.github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { zodGithubAccessToken } from "@/zod/zod.common";
import { App, Octokit } from "octokit";
import fs from 'fs';

export const getOctokit = async ({
installationId,
accessToken,
}: {
installationId?: number;
accessToken?: string;
}) => {
try {
if (installationId) {
const appId = process.env.AUSPY_GITHUB_APP_ID;

const base64Key = process.env.AUSPY_GITHUB_PRIVATE_KEY;
if (!base64Key) {
throw new Error("Private Key not found");
}
// Decode the Base64-encoded key to binary data
const binaryKey = Buffer.from(base64Key, "base64");
// Convert the binary key to a string
const stringKey = binaryKey.toString("utf8");

if (!appId || !stringKey) {
throw new Error("App ID or Private Key not found");
}
const app = new App({
appId,
privateKey: stringKey,
});
return {
api: await app.getInstallationOctokit(installationId),
type: "app",
};


// const appId = process.env.AUSPY_GITHUB_APP_ID;
// const filepath = './devclans-local.pem';

// const base64Key = fs
// .readFileSync(filepath, "base64")
// .replace("-----BEGIN RSA PRIVATE KEY-----", "")
// .replace("-----END RSA PRIVATE KEY-----", "")
// .trim();
// // Decode the Base64-encoded key to binary data
// const binaryKey = Buffer.from(base64Key, "base64");

// // Convert the binary key to a string (optional)
// const stringKey = binaryKey.toString("utf8");
// // console.log("My key is: ", myKey);
// if (!appId || !base64Key) {
// throw new Error("App ID or Private Key not found");
// }
// const app = new App({
// appId,
// privateKey: stringKey,
// });
// return {
// api: await app.getInstallationOctokit(installationId),
// type: "app",
// };

} else if (zodGithubAccessToken.safeParse(accessToken).success) {
return {
api: new Octokit({
auth: accessToken,
}),
type: "auth",
};
} else {
return { api: new Octokit({}), type: "free" };
}
} catch (error) {
console.error("Error getting octokit", error);
return null;
}
};

Binary file added public/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/app/api/auth/github/appcallback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const dynamic = "force-dynamic";
const handler = async (req: NextRequest) => {
try {
console.log(" start of github/appcallback");
// const code = req.nextUrl.searchParams.get("code");
const code = req.nextUrl.searchParams.get("code");
const setupAction = req.nextUrl.searchParams.get("setup_action");
console.log(setupAction, code);
console.log(req.nextUrl.searchParams.get("installation_id"))
const installId = zodGithubInstallationId.parse(
req.nextUrl.searchParams.get("installation_id")
);
Expand All @@ -26,6 +29,7 @@ const handler = async (req: NextRequest) => {
const userId = zodMongoId.parse(session?.user?._id);
// get installed repos
const reposData = await getInstalledReposFunc(installId, false);
console.log(reposData)
// get user profile
await updateData(userId, installId, reposData);
console.log("success of github/appcallback, redirecting");
Expand Down
44 changes: 44 additions & 0 deletions src/app/api/joinTeam/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// app/api/join-team/route.ts
import { NextRequest, NextResponse } from 'next/server';
import dbConnect from '@/lib/dbConnect';
import { ProjectModel } from '@/mongodb/models';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/utils/auth/auth';
export async function POST(req: NextRequest,res:NextResponse) {
const session: any = await getServerSession(authOptions);
console.log(session);
const userId = session.user._id;
const { teamCode } = await req.json();
try {


await dbConnect();

// Find the project with the provided team code
const project = await ProjectModel.findOne({ teamCode });

if (!project) {
return NextResponse.json({ error: 'Project not found' }, { status: 404 });
}


console.log(userId);

// Add the user's ID to the contributors array
if(userId){
project.team.push(userId);
await project.save();


return NextResponse.json({ message: 'Joined team successfully' });
}
else{
return NextResponse.json({ error: 'User not found' }, { status: 404 });
}


} catch (error) {
console.error('Error joining team:', error);
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
}
}
105 changes: 105 additions & 0 deletions src/app/api/leetcode/getUserProfile/[username]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { NextRequest, NextResponse } from "next/server";

async function handler(req:NextRequest, { params }: { params: { username: string } }){
try{
const username = params.username;
const query = `
query getUserProfile($username: String!) {
allQuestionsCount {
difficulty
count
}
matchedUser(username: $username) {
contributions {
points
}
profile {
reputation
ranking
}
submissionCalendar
submitStats {
acSubmissionNum {
difficulty
count
submissions
}
totalSubmissionNum {
difficulty
count
submissions
}
}
}
recentSubmissionList(username: $username) {
title
titleSlug
timestamp
statusDisplay
lang
__typename
}
matchedUserStats: matchedUser(username: $username) {
submitStats: submitStatsGlobal {
acSubmissionNum {
difficulty
count
submissions
__typename
}
totalSubmissionNum {
difficulty
count
submissions
__typename
}
__typename
}
}
}
`;

const formatData = (data:any) => {
let sendData = {
totalSolved: data.data.matchedUser.submitStats.acSubmissionNum[0].count,
totalSubmissions: data.data.matchedUser.submitStats.totalSubmissionNum,
totalQuestions: data.data.allQuestionsCount[0].count,
easySolved: data.data.matchedUser.submitStats.acSubmissionNum[1].count,
totalEasy: data.data.allQuestionsCount[1].count,
mediumSolved: data.data.matchedUser.submitStats.acSubmissionNum[2].count,
totalMedium: data.data.allQuestionsCount[2].count,
hardSolved: data.data.matchedUser.submitStats.acSubmissionNum[3].count,
totalHard: data.data.allQuestionsCount[3].count,
ranking: data.data.matchedUser.profile.ranking,
contributionPoint: data.data.matchedUser.contributions.points,
reputation: data.data.matchedUser.profile.reputation,
submissionCalendar: JSON.parse(data.data.matchedUser.submissionCalendar),
recentSubmissions: data.data.recentSubmissionList,
matchedUserStats: data.data.matchedUser.submitStats
}
return sendData;
}
const response = await fetch('https://leetcode.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Referer': 'https://leetcode.com',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers':'Content-Type, application/json'
},
body: JSON.stringify({query: query, variables: {username: username}}),
});
const data = await response.json();

return NextResponse.json({ data: formatData(data)}, {status: 200});


}
catch(error){
console.error('Error getting user profile:', error);
return NextResponse.json({ error: 'Error getting user profile' }, { status: 500 });
}
}

export { handler as GET };
2 changes: 1 addition & 1 deletion src/app/api/project/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDataQuery } from "@/utils/getDataQuery";

async function handler(req: Request) {
async function handler(req: Request):Promise<any>{
return getDataQuery(req.url);
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/explore/projects/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Projects = async ({ params, searchParams }: Partial<PageProps>) => {
const projects: ProjectSearchItemProps[] =
(await Fetch({
endpoint: "/project" + (str ? `?${str}` : ""),
revalidate: 3600 * 3, // TODO - set revalidate time
revalidate: 1, // TODO - set revalidate time
})) || [];
console.log(
Array.isArray(projects) && projects.length > 0,
Expand Down
Loading