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
11 changes: 10 additions & 1 deletion src/app/api/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ export const runtime = "nodejs";
export async function POST(req: Request) {
try {
const formData = await req.formData();
const files = formData.getAll("files").filter(Boolean) as File[];
const uploads = formData.getAll("files");
const files = uploads.filter((upload): upload is File => typeof upload !== "string");
const isPdf = formData.get("isPdf") === "true";
const thumbnail = formData.get("thumbnail") as File | null;
const campus = formData.get("campus") as string | null;

if (files.length !== uploads.length) {
return failure("every entry in files has to be a file", 400);
}

if (isPdf && files.length > 1) {
return failure("upload one pdf at a time", 400);
}

if (files.length === 0) {
return failure("No files received.", 400);
}
Expand Down
13 changes: 10 additions & 3 deletions src/app/api/user-papers/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { type StoredSubjects } from "@/interface";
import { z } from "zod";
import { getPapersBySubjects } from "@/lib/services/paper"
import { success, failure } from "@/lib/utils/response";

export const dynamic = "force-dynamic";

const pinnedSubjects = z.array(z.string().trim().min(1).max(200)).max(100);

export async function POST(req: Request) {
try {
const subjects = (await req.json()) as StoredSubjects;
const body: unknown = await req.json().catch(() => null);
const subjects = pinnedSubjects.safeParse(body);

if (!subjects.success) {
return failure("send a list of up to 100 subject names", 400);
}

const transformedPapers = await getPapersBySubjects(subjects)
const transformedPapers = await getPapersBySubjects(subjects.data)

return success(transformedPapers);
} catch (error) {
Expand Down