Skip to content

Commit f09ed99

Browse files
fixed year detection
1 parent aac17a2 commit f09ed99

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

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

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function POST(req: Request) {
3939
const formData = await req.formData();
4040
const files: File[] = formData.getAll("files") as File[];
4141
const isPdf = formData.get("isPdf") === "true"; // Convert string to boolean
42-
42+
4343
const orderedFiles = Array.from(files).sort((a, b) => {
4444
return a.name.localeCompare(b.name);
4545
});
@@ -61,53 +61,53 @@ export async function POST(req: Request) {
6161
const slot = finalTags.slot;
6262
const exam = finalTags["exam-type"];
6363
const year = finalTags.year;
64-
const campus = formData.get("campus") as string
64+
const campus = formData.get("campus") as string;
6565
const semester = finalTags.semester;
6666

6767
if (!courses.includes(subject)) {
6868
return NextResponse.json(
6969
{ message: "The course subject is invalid." },
70-
{ status: 400 }
70+
{ status: 400 },
7171
);
7272
}
73-
73+
7474
if (!slots.includes(slot)) {
7575
return NextResponse.json(
7676
{ message: "The slot is invalid." },
77-
{ status: 400 }
77+
{ status: 400 },
7878
);
7979
}
80-
80+
8181
if (!exam.includes(exam)) {
8282
return NextResponse.json(
8383
{ message: "The exam type is invalid." },
84-
{ status: 400 }
84+
{ status: 400 },
8585
);
8686
}
87-
87+
8888
if (!years.includes(year)) {
8989
return NextResponse.json(
9090
{ message: "The year is invalid." },
91-
{ status: 400 }
91+
{ status: 400 },
9292
);
9393
}
94-
94+
9595
if (!campuses.includes(campus)) {
9696
return NextResponse.json(
97-
{ message:`The ${campus} is invalid.` },
98-
{ status: 400 }
97+
{ message: `The ${campus} is invalid.` },
98+
{ status: 400 },
9999
);
100100
}
101-
101+
102102
if (!semesters.includes(semester)) {
103103
return NextResponse.json(
104104
{ message: "The semester is invalid." },
105-
{ status: 400 }
105+
{ status: 400 },
106106
);
107107
}
108-
108+
109109
// If all checks pass, continue with the rest of the logic
110-
110+
111111
await connectToDatabase();
112112
let finalUrl: string | undefined = "";
113113
let public_id_cloudinary: string | undefined = "";
@@ -163,10 +163,7 @@ export async function POST(req: Request) {
163163
semester,
164164
});
165165
await paper.save();
166-
return NextResponse.json(
167-
{ status: "success", },
168-
{ status: 201 },
169-
);
166+
return NextResponse.json({ status: "success" }, { status: 201 });
170167
} catch (error) {
171168
console.error(error);
172169
return NextResponse.json(
@@ -290,11 +287,6 @@ async function setTagsFromCurrentLists(
290287
}
291288
function findMatch<T>(arr: T[], value: string | undefined): T | undefined {
292289
if (!value) return undefined; // Handle undefined case
293-
const pattern = new RegExp(
294-
value
295-
.split("")
296-
.map((char) => `(?=.*${char})`)
297-
.join(""),
298-
"i"
299-
); return arr.find((item) => pattern.test(String(item)));
300-
}
290+
const pattern = new RegExp(value, "i");
291+
return arr.find((item) => pattern.test(String(item)));
292+
}

0 commit comments

Comments
 (0)