Skip to content

Commit f905f31

Browse files
bulk upload
1 parent 61d6686 commit f905f31

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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: { status: string; url: string; thumbnailUrl: string }[] = [];
18+
19+
await Promise.all(
20+
body.map(async (paperData) => {
21+
const { url, slot, subject, exam, year } = paperData;
22+
23+
const existingPaper = await Paper.findOne({
24+
subject,
25+
slot,
26+
year,
27+
exam,
28+
});
29+
if (existingPaper) {
30+
responseArray.push({
31+
status: "Paper already exists",
32+
url: "",
33+
thumbnailUrl: "",
34+
});
35+
return;
36+
}
37+
38+
const thumbnailResponse = cloudinary.v2.image(url, { format: "jpg" });
39+
const thumbnailUrl = thumbnailResponse
40+
.replace("pdf", "jpg")
41+
.replace("upload", "upload/w_400,h_400,c_fill")
42+
.replace(/<img src='|'\s*\/>/g, '');
43+
44+
const paper = new Paper({
45+
finalUrl: url,
46+
thumbnailUrl,
47+
subject,
48+
slot,
49+
year,
50+
exam,
51+
});
52+
53+
await paper.save();
54+
55+
responseArray.push({
56+
status: "success",
57+
url: url,
58+
thumbnailUrl: thumbnailUrl,
59+
});
60+
}),
61+
);
62+
63+
return NextResponse.json(responseArray, { status: 201 });
64+
} catch (error) {
65+
console.error(error);
66+
return NextResponse.json(
67+
{ message: "Failed to upload papers", error },
68+
{ status: 500 },
69+
);
70+
}
71+
}
72+

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)