Skip to content

Commit a3adf41

Browse files
Merge pull request #31 from CodeChefVIT/staging
Staging
2 parents 5f21280 + 2c2064f commit a3adf41

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { NextResponse } from "next/server";
2+
import { connectToDatabase } from "@/lib/mongoose";
3+
import cloudinary from "cloudinary";
4+
import Paper from "@/db/papers";
5+
6+
export async function POST(req: Request) {
7+
try {
8+
await connectToDatabase();
9+
const body = (await req.json()) as Array<{
10+
url: string;
11+
slot: string;
12+
subject: string;
13+
exam: string;
14+
year: number;
15+
}>;
16+
17+
const responseArray: {
18+
status: string;
19+
url: string;
20+
thumbnailUrl: string;
21+
subject: string;
22+
slot: string;
23+
year: number;
24+
}[] = [];
25+
26+
await Promise.all(
27+
body.map(async (paperData) => {
28+
const { url, slot, subject, exam, year } = paperData;
29+
30+
const existingPaper = await Paper.findOne({
31+
subject,
32+
slot,
33+
year,
34+
exam,
35+
});
36+
if (existingPaper) {
37+
responseArray.push({
38+
status: "Paper already exists",
39+
url: "",
40+
thumbnailUrl: "",
41+
subject,
42+
slot,
43+
year,
44+
});
45+
return;
46+
}
47+
48+
const thumbnailResponse = cloudinary.v2.image(url, { format: "jpg" });
49+
const thumbnailUrl = thumbnailResponse
50+
.replace("pdf", "jpg")
51+
.replace("upload", "upload/w_400,h_400,c_fill")
52+
.replace(/<img src='|'\s*\/>/g, "");
53+
54+
const paper = new Paper({
55+
finalUrl: url,
56+
thumbnailUrl,
57+
subject,
58+
slot,
59+
year,
60+
exam,
61+
});
62+
63+
await paper.save();
64+
65+
responseArray.push({
66+
status: "success",
67+
url: url,
68+
thumbnailUrl: thumbnailUrl,
69+
});
70+
}),
71+
);
72+
73+
return NextResponse.json(responseArray, { status: 201 });
74+
} catch (error) {
75+
console.error(error);
76+
return NextResponse.json(
77+
{ message: "Failed to upload papers", error },
78+
{ status: 500 },
79+
);
80+
}
81+
}

src/app/upload/select_options.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ const courses = [
7575
"Blockchain Technology [BITE414L]",
7676
"Quantum Computing [BITE407L]",
7777
"Engineering Optimization [BITE415L]",
78+
"Engineering Optimization [BMEE215L]",
7879
"Biology [BBIT100L]",
7980
"Biobusiness [BBIT311L]",
8081
"AWS Solutions Architect [BCSE355L]",
8182
"Electronic Materials and Devices [BECE201L]",
83+
"Materials Science and Engineering [BMEE209L]",
8284
"Electromagnetic Theory [BEEE202L]",
8385
"Rural Development [BHUM202L]",
8486
"Circuit Theory [BECE203L]",
@@ -92,19 +94,26 @@ const courses = [
9294
"Game Theory [BHUM209L]",
9395
"Behavioral Economics [BHUM211L]",
9496
"Econometrics [BHUM210E]",
97+
"Fluid Mechanics and Machines [BMEE204L]",
98+
"Cloud Computing using Salesforce [BMEE355L]",
99+
"Metal Casting and Welding [BMEE302L]",
100+
"Metal Forming and Machining [BMEE304L]",
95101
"Contemporary India [BHUM217L]",
96102
"Mathematics for Economic Analysis [BHUM212L]",
97103
"Corporate Social Responsibility [BHUM213L]",
98104
"Political Science [BHUM214L]",
99105
"Economics of Money, Banking and Financial Markets [BHUM221L]",
106+
"Kinematics and Dynamics of Machines [BMEE207L]",
100107
"Financial Management [BHUM218L]",
101108
"Security Analysis and Portfolio Management [BHUM222L]",
102109
"Indian Culture and Heritage [BHUM216L]",
110+
"Mechatronics and Measurement Systems [BMEE210L]",
103111
"International Relations [BHUM215L]",
104112
"Financial Markets and Institutions [BHUM220L]",
105113
"Principles of Accounting [BHUM219L]",
106114
"Options , Futures and other Derivatives [BHUM223L]",
107115
"Corporate Finance [BHUM226L]",
116+
"Engineering Thermodynamics [BMEE203L]",
108117
"Fixed Income Securities [BHUM224L]",
109118
"Personal Finance [BHUM225L]",
110119
"Cost and Management Accounting [BHUM228L]",
@@ -117,10 +126,13 @@ const courses = [
117126
"Taxation [BHUM236L]",
118127
"Psychology of Wellness [BHUM235E]",
119128
"Indian Psychology [BHUM234L]",
129+
"Design of Machine Elements [BMEE301L]",
130+
"Thermal Engineering Systems [BMEE303L]",
120131
"Mathematics [BMAT100L]",
121132
"Engineering Design Visualisation Lab [BMEE102P]",
122133
"Engineering Mechanics [BMEE201L]",
123134
"Entrepreneurship [BMGT108L]",
135+
"Mechanics of Solids [BMEE202L]",
124136
"Introduction to Intellectual Property [BMGT109L]",
125137
"Optics [BPHY201L]",
126138
"Computational Physics [BPHY301E]",

0 commit comments

Comments
 (0)