Files
vfxreview/lib/uploadthing.ts
T
twotalesanimation 0fbe856dce Initial commit
2026-05-19 22:20:29 +02:00

41 lines
1.1 KiB
TypeScript

import { createUploadthing, type FileRouter } from "uploadthing/next";
import { auth } from "@/auth";
const f = createUploadthing();
export const uploadRouter = {
/** Full-resolution video upload (mp4, mov) */
versionVideo: f({
video: {
maxFileSize: "2GB",
maxFileCount: 1,
},
})
.middleware(async () => {
const session = await auth();
if (!session?.user) throw new Error("Unauthorized");
return { userId: session.user.id };
})
.onUploadComplete(async ({ metadata, file }) => {
return { uploadedBy: metadata.userId, url: file.url };
}),
/** Thumbnail / poster image upload */
versionThumbnail: f({
image: {
maxFileSize: "4MB",
maxFileCount: 1,
},
})
.middleware(async () => {
const session = await auth();
if (!session?.user) throw new Error("Unauthorized");
return { userId: session.user.id };
})
.onUploadComplete(async ({ metadata, file }) => {
return { uploadedBy: metadata.userId, url: file.url };
}),
} satisfies FileRouter;
export type OurFileRouter = typeof uploadRouter;