export const uploadRouter = {
inputSource: f({
image: {
maxFileSize: '8MB',
maxFileCount: 1,
},
})
.middleware(async () => {
const { userId } = await auth();
if (!userId) throw new UploadThingError('Unauthorized');
return { userId };
})
.onUploadComplete(async ({ file }) => {
const caller = appRouter.createCaller(await createTRPCContext());
const { error } = await tryCatch(
caller.input.createInputSource({
url: file.ufsUrl,
type: 'IMAGE',
}),
);
if (error) throw new UploadThingError(error.message);
}),
} satisfies FileRouter;
export const uploadRouter = {
inputSource: f({
image: {
maxFileSize: '8MB',
maxFileCount: 1,
},
})
.middleware(async () => {
const { userId } = await auth();
if (!userId) throw new UploadThingError('Unauthorized');
return { userId };
})
.onUploadComplete(async ({ file }) => {
const caller = appRouter.createCaller(await createTRPCContext());
const { error } = await tryCatch(
caller.input.createInputSource({
url: file.ufsUrl,
type: 'IMAGE',
}),
);
if (error) throw new UploadThingError(error.message);
}),
} satisfies FileRouter;