41 lines
1.1 KiB
TypeScript
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;
|