import { validateRequest } from "@/lib/lucia";
import { createUploadthing, type FileRouter } from "uploadthing/next";
import { UploadThingError } from "uploadthing/server";
const f = createUploadthing();
export const ourFileRouter = {
imageUploader: f({
image: { maxFileSize: "4MB" },
pdf: { maxFileSize: "8MB" },
"application/zip": { maxFileSize: "8MB" },
})
.middleware(async ({ req }) => {
const { session } = await validateRequest();
if (!session) throw new UploadThingError("Unauthorized");
return { userId: session.userId };
})
.onUploadComplete(async ({ metadata, file }) => {
return { uploadedBy: metadata.userId, file };
}),
} satisfies FileRouter;
export type OurFileRouter = typeof ourFileRouter;