Skip to content

Commit 09e972e

Browse files
Merge pull request #232 from Advik-Gupta/staging
Fixed merge issues and optimized variable names
2 parents cebc2b9 + c38c0b6 commit 09e972e

File tree

18 files changed

+513
-451
lines changed

18 files changed

+513
-451
lines changed

ongoing-papers.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const papers: IUpcomingPaper[] = [
55
_id: "6708fd8002a75017a4f08759",
66
subject: "Discrete Mathematics and Graph Theory [BMAT205L]",
77
slots: ["A2", "B2"],
8-
98
},
109
{
1110
_id: "670980523ec3fdad83b2d211",
@@ -15,9 +14,9 @@ const papers: IUpcomingPaper[] = [
1514
{
1615
_id: "670a105e6272bcf9da4e2362",
1716

18-
finalUrl:
17+
final_url:
1918
"https://res.cloudinary.com/dtorpaj1c/image/upload/v1728712773/papers/ifkrnjgwdudtev9rxpki.pdf",
20-
thumbnailUrl:
19+
thumbnail_url:
2120
"https://res.cloudinary.com/dtorpaj1c/image/upload/w_400,h_400,c_fill/v1728712773/papers/ifkrnjgwdudtev9rxpki.jpg",
2221
subject: "Complex Variables and Linear Algebra [BMAT201L]",
2322
slots: ["A1", "B1"],
@@ -28,9 +27,9 @@ const papers: IUpcomingPaper[] = [
2827
},
2928
{
3029
_id: "67097e7b3ec3fdad83b2d205",
31-
finalUrl:
30+
final_url:
3231
"https://res.cloudinary.com/dtorpaj1c/image/upload/v1728675439/papers/pyyqotz1mzuh2wmq1k9s.pdf",
33-
thumbnailUrl:
32+
thumbnail_url:
3433
"https://res.cloudinary.com/dtorpaj1c/image/upload/w_400,h_400,c_fill/v1728675439/papers/pyyqotz1mzuh2wmq1k9s.jpg",
3534
subject: "Computer Networks [BCSE308L]",
3635
slots: ["C2", "D2"],

src/app/api/papers/route.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,34 @@ export async function GET(req: NextRequest) {
3030
return NextResponse.json(
3131
{
3232
papers,
33-
uniqueYears: [],
34-
uniqueSlots: [],
35-
uniqueExams: [],
36-
uniqueCampuses: [],
37-
uniqueSemesters: [],
33+
unique_years: [],
34+
unique_slots: [],
35+
unique_exams: [],
36+
unique_campuses: [],
37+
unique_semesters: [],
3838
},
3939
{ status: 200 },
4040
);
4141
}
4242

43-
const uniqueYears = Array.from(new Set(papers.map((paper) => paper.year)));
44-
const uniqueSlots = Array.from(new Set(papers.map((paper) => paper.slot)));
45-
const uniqueExams = Array.from(new Set(papers.map((paper) => paper.exam)));
46-
const uniqueCampuses = Array.from(
43+
const unique_years = Array.from(new Set(papers.map((paper) => paper.year)));
44+
const unique_slots = Array.from(new Set(papers.map((paper) => paper.slot)));
45+
const unique_exams = Array.from(new Set(papers.map((paper) => paper.exam)));
46+
const unique_campuses = Array.from(
4747
new Set(papers.map((paper) => paper.campus)),
4848
);
49-
const uniqueSemesters = Array.from(
49+
const unique_semesters = Array.from(
5050
new Set(papers.map((paper) => paper.semester)),
5151
);
5252

5353
return NextResponse.json(
5454
{
5555
papers,
56-
uniqueYears,
57-
uniqueSlots,
58-
uniqueExams,
59-
uniqueCampuses,
60-
uniqueSemesters,
56+
unique_years,
57+
unique_slots,
58+
unique_exams,
59+
unique_campuses,
60+
unique_semesters,
6161
},
6262
{ status: 200 },
6363
);

src/app/api/ai-upload/route.ts renamed to src/app/api/upload/route.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ const cloudinaryConfigs = [config1, config2];
2828
export async function POST(req: Request) {
2929
try {
3030
if (!process.env.NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET) {
31-
return NextResponse.json({ message: "ServerMisconfig" }, { status: 500 });
31+
return NextResponse.json(
32+
{ message: "ServerMisconfiguration" },
33+
{ status: 500 },
34+
);
3235
}
3336
await connectToDatabase();
3437
const count: number = await PaperAdmin.countDocuments();
@@ -54,9 +57,9 @@ export async function POST(req: Request) {
5457
pdfData = pdfBuffer.toString("base64");
5558
}
5659

57-
let finalUrl: string | undefined = "";
60+
let final_url: string | undefined = "";
5861
let public_id_cloudinary: string | undefined = "";
59-
let thumbnailUrl: string | undefined = "";
62+
let thumbnail_url: string | undefined = "";
6063

6164
if (!files || files.length === 0) {
6265
return NextResponse.json(
@@ -71,15 +74,11 @@ export async function POST(req: Request) {
7174
return;
7275
}
7376

74-
console.log("this is happening 1");
75-
7677
const mergedPdfBytes = await CreatePDF(files);
77-
[public_id_cloudinary, finalUrl] = await uploadPDFFile(
78+
[public_id_cloudinary, final_url] = await uploadPDFFile(
7879
mergedPdfBytes,
7980
uploadPreset,
8081
);
81-
82-
console.log("this is happening 2");
8382
} catch (error) {
8483
console.error("Error creating PDF:", error);
8584
return NextResponse.json(
@@ -88,28 +87,25 @@ export async function POST(req: Request) {
8887
);
8988
}
9089
} else {
91-
console.log("this is happening 3");
92-
[public_id_cloudinary, finalUrl] = await uploadPDFFile(
90+
[public_id_cloudinary, final_url] = await uploadPDFFile(
9391
files[0]!,
9492
uploadPreset,
9593
);
9694
}
9795

98-
const thumbnailResponse = cloudinary.v2.image(finalUrl!, {
96+
const thumbnailResponse = cloudinary.v2.image(final_url!, {
9997
format: "jpg",
10098
});
101-
thumbnailUrl = thumbnailResponse
99+
thumbnail_url = thumbnailResponse
102100
.replace("pdf", "jpg")
103101
.replace("upload", "upload/w_400,h_400,c_fill")
104102
.replace(/<img src='|'\s*\/>/g, "");
105103

106-
console.log("this is happening 4");
107-
108104
const paper = new PaperAdmin({
109105
cloudinary_index: configIndex,
110106
public_id_cloudinary,
111-
finalUrl,
112-
thumbnailUrl,
107+
final_url,
108+
thumbnail_url,
113109
subject: null,
114110
slot: null,
115111
year: null,
@@ -118,9 +114,7 @@ export async function POST(req: Request) {
118114
campus: null,
119115
});
120116

121-
console.log("this is happening 5");
122117
await paper.save();
123-
console.log("this is happening 6");
124118
return NextResponse.json({ status: "success" }, { status: 201 });
125119
} catch (error) {
126120
console.error(error);
@@ -132,7 +126,6 @@ export async function POST(req: Request) {
132126
}
133127

134128
async function uploadPDFFile(file: File | ArrayBuffer, uploadPreset: string) {
135-
console.log("this is happening 7");
136129
let bytes;
137130
if (file instanceof File) {
138131
bytes = await file.arrayBuffer();
@@ -148,16 +141,14 @@ async function uploadFile(
148141
fileType: string,
149142
) {
150143
try {
151-
console.log("this is happening 8");
152144
const buffer = Buffer.from(bytes);
153-
console.log("this is happening 9");
154145
const dataUrl = `data:${fileType};base64,${buffer.toString("base64")}`;
155-
console.log("this is happening 10");
146+
156147
const uploadResult = (await cloudinary.v2.uploader.unsigned_upload(
157148
dataUrl,
158149
uploadPreset,
159150
)) as CloudinaryUploadResult;
160-
console.log("this is happening 11");
151+
161152
return [uploadResult.public_id, uploadResult.secure_url];
162153
} catch (e) {
163154
throw e;

src/app/api/user-papers/route.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ export async function POST(req: Request) {
1919
subject: { $in: subjects },
2020
});
2121

22-
const transformedPapers = usersPapers.reduce(
23-
(acc: { subject: string; slots: string[] }[], paper) => {
22+
const transformedPapers = usersPapers.reduce<TransformedPaper[]>(
23+
(acc, paper) => {
2424
const existing = acc.find((item) => item.subject === paper.subject);
2525

26+
if (existing) {
27+
existing.slots.push(paper.slot);
28+
} else {
29+
acc.push({ subject: paper.subject, slots: [paper.slot] });
30+
}
2631
if (existing) {
2732
existing.slots.push(paper.slot);
2833
} else {
@@ -34,14 +39,7 @@ export async function POST(req: Request) {
3439
[],
3540
);
3641

37-
const seenSubjects = new Set();
38-
const uniquePapers = transformedPapers.filter((paper) => {
39-
if (seenSubjects.has(paper.subject)) return false;
40-
seenSubjects.add(paper.subject);
41-
return true;
42-
});
43-
44-
return NextResponse.json(uniquePapers, {
42+
return NextResponse.json(transformedPapers, {
4543
status: 200,
4644
});
4745
} catch (error) {

src/app/layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { Metadata } from "next";
77
import Navbar from "@/components/Navbar";
88
import Footer from "@/components/Footer";
99
import ChildrenWrapper from "@/components/ChildrenWrapper";
10-
import Banner from "@/components/BannerAlert";
1110

1211
export const metadata: Metadata = {
1312
metadataBase: new URL("https://papers.codechefvit.com/"),

src/app/paper/[id]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ const PaperPage = async ({ params }: { params: { id: string } }) => {
158158
</div>
159159
) : (
160160
<>
161+
<h1 className="my-6 flex justify-center gap-4 text-center font-play text-2xl font-semibold md:mb-10 md:text-3xl">
161162
<h1 className="my-6 flex justify-center gap-4 text-center font-play text-2xl font-semibold md:mb-10 md:text-3xl">
162163
<div>
163164
{paper.subject} {paper.exam} {paper.slot} {paper.year}
164165
</div>
165166
</h1>
166167
<center>
167168
<PdfViewer
168-
// url={paper.finalUrl}
169-
url="https://res.cloudinary.com/dq6tapd4t/image/upload/v1746291007/sck2vipdklqaurwhipjl.pdf"
169+
url={paper.final_url}
170170
name={`${extractBracketContent(paper.subject)}-${paper.exam}-${paper.slot}-${paper.year}`}
171171
></PdfViewer>
172172
</center>

src/app/upload/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ const Page = () => {
140140
await toast.promise(
141141
async () => {
142142
try {
143-
await axios.post<APIResponse>("/api/ai-upload", formData);
143+
console.log("this is happening now");
144+
await axios.post<APIResponse>("/api/upload", formData);
145+
console.log("this is happening after now");
146+
return { message: "Papers uploaded successfully!" };
144147
} catch (error) {
145148
if (error instanceof AxiosError && error.response?.data) {
146149
const errorData = error.response.data as APIResponse;
@@ -173,7 +176,7 @@ const Page = () => {
173176
const isCurrentlyDragging = isDragging || isGlobalDragging;
174177

175178
return (
176-
<div className="font-play flex h-[calc(100vh-85px)] flex-col justify-center px-6">
179+
<div className="flex h-[calc(100vh-85px)] flex-col justify-center px-6 font-play">
177180
<div className="2xl:my-15 flex flex-col items-center">
178181
<fieldset className="mb-4 w-full max-w-md rounded-lg border-2 border-gray-300 p-4 pr-8">
179182
<div className="flex w-full flex-col 2xl:gap-y-4">

src/components/Card.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const Card = ({ paper, onSelect, isSelected }: CardProps) => {
3030
url.startsWith("http://") ? url.replace("http://", "https://") : url;
3131

3232
const generateFileName = (paper: IPaper): string => {
33-
const extension = paper.finalUrl.split(".").pop();
33+
const extension = paper.final_url.split(".").pop();
3434
return `${extractBracketContent(paper.subject)}-${paper.exam}-${paper.slot}-${paper.year}.${extension}`;
3535
};
3636

@@ -49,7 +49,7 @@ const Card = ({ paper, onSelect, isSelected }: CardProps) => {
4949
};
5050

5151
const handleDownload = async (paper: IPaper) => {
52-
await downloadFile(getSecureUrl(paper.finalUrl), generateFileName(paper));
52+
await downloadFile(getSecureUrl(paper.final_url), generateFileName(paper));
5353
};
5454

5555
const handleCheckboxChange = () => {
@@ -65,14 +65,14 @@ const Card = ({ paper, onSelect, isSelected }: CardProps) => {
6565
return (
6666
<div
6767
className={cn(
68+
"overflow-hidden rounded-sm border-2 border-[#734DFF] bg-[#FFFFFF] font-play transition-all duration-150 hover:bg-[#EFEAFF] dark:border-[#36266D] dark:bg-[#171720] hover:dark:bg-[#262635]",
6869
"overflow-hidden rounded-sm border-2 border-[#734DFF] bg-[#FFFFFF] font-play transition-all duration-150 hover:bg-[#EFEAFF] dark:border-[#36266D] dark:bg-[#171720] hover:dark:bg-[#262635]",
6970
checked && "bg-white",
7071
)}
7172
>
7273
<Link href={paperLink} target="_blank" rel="noopener noreferrer">
7374
<Image
74-
// src={paper.thumbnailUrl}
75-
src="https://res.cloudinary.com/dq6tapd4t/image/upload/w_400,h_400,c_fill/v1746291007/sck2vipdklqaurwhipjl.jpg"
75+
src={paper.thumbnail_url}
7676
alt={paper.subject}
7777
width={320}
7878
height={180}
@@ -81,6 +81,7 @@ const Card = ({ paper, onSelect, isSelected }: CardProps) => {
8181

8282
<div className="justify-center">
8383
<div className="flex flex-row items-center justify-between px-4 pb-2">
84+
<div className="text-md font-play font-medium">
8485
<div className="text-md font-play font-medium">
8586
{extractBracketContent(paper.subject)}
8687
</div>
@@ -116,6 +117,7 @@ const Card = ({ paper, onSelect, isSelected }: CardProps) => {
116117
</div>
117118
</Link>
118119

120+
<div className="hidden items-center justify-between gap-2 px-4 pb-4 font-play md:flex">
119121
<div className="hidden items-center justify-between gap-2 px-4 pb-4 font-play md:flex">
120122
<div className="flex items-center gap-2">
121123
<input
@@ -126,7 +128,7 @@ const Card = ({ paper, onSelect, isSelected }: CardProps) => {
126128
/>
127129
<p>Select</p>
128130
</div>
129-
{paper.answerKeyIncluded && (
131+
{paper.answer_key_included && (
130132
<div className="flex items-center gap-2 font-normal text-[#7480FF]">
131133
<Check color="#7480FF" />
132134
Answer Key

0 commit comments

Comments
 (0)