feat: random mii button

This commit is contained in:
trafficlunar 2025-03-31 18:09:51 +01:00
parent a806003bc6
commit 2fdf120280

18
src/app/random/route.ts Normal file
View file

@ -0,0 +1,18 @@
import { redirect } from "next/navigation";
import { prisma } from "@/lib/prisma";
export async function GET() {
const count = await prisma.mii.count();
if (count === 0) redirect("/");
const randomIndex = Math.floor(Math.random() * count);
const randomMii = await prisma.mii.findFirst({
skip: randomIndex,
take: 1,
select: { id: true },
});
if (!randomMii) redirect("/");
redirect(`/mii/${randomMii.id}`);
}