feat: random mii button
This commit is contained in:
parent
a806003bc6
commit
2fdf120280
1 changed files with 18 additions and 0 deletions
18
src/app/random/route.ts
Normal file
18
src/app/random/route.ts
Normal 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}`);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue