23 lines
703 B
TypeScript
23 lines
703 B
TypeScript
import { createUploadthing, type FileRouter as UploadThingFileRouter } from "uploadthing/next";
|
|
import { UTApi } from 'uploadthing/server'
|
|
import { isAdmin } from "~/app/actions";
|
|
|
|
const f = createUploadthing();
|
|
|
|
export const fileRouter = {
|
|
musicUploader: f({ audio: { maxFileSize: "64MB", maxFileCount: 1 } })
|
|
.middleware(async () => {
|
|
const admin = await isAdmin();
|
|
if (!admin) throw new Error("Unauthorized");
|
|
return {};
|
|
})
|
|
.onUploadComplete(async ({ file }) => {
|
|
console.log(file)
|
|
return { fileUrl: file.ufsUrl, fileKey: file.key, fileName: file.name };
|
|
}),
|
|
} satisfies UploadThingFileRouter ;
|
|
|
|
export type FileRouter = typeof fileRouter;
|
|
|
|
export const utapi = new UTApi();
|