fix: parity with vite-split

idk what to use
This commit is contained in:
trafficlunar 2026-04-22 11:45:54 +01:00
parent 5235efdd2e
commit aa631095fa
9 changed files with 37 additions and 137 deletions

View file

@ -3,5 +3,3 @@ ALTER TABLE "miis" ADD COLUMN "likeCount" INTEGER NOT NULL DEFAULT 0;
-- CreateIndex -- CreateIndex
CREATE INDEX "miis_likeCount_idx" ON "miis"("likeCount" DESC); CREATE INDEX "miis_likeCount_idx" ON "miis"("likeCount" DESC);
UPDATE miis SET "likeCount" = (SELECT COUNT(*) FROM likes WHERE likes."miiId" = miis.id);

View file

@ -0,0 +1,25 @@
/*
Warnings:
- You are about to drop the column `punishmentId` on the `miis` table. All the data in the column will be lost.
- You are about to drop the column `notes` on the `punishments` table. All the data in the column will be lost.
- You are about to drop the column `reasons` on the `punishments` table. All the data in the column will be lost.
- You are about to drop the `mii_punishments` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `reason` to the `punishments` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "mii_punishments" DROP CONSTRAINT "mii_punishments_miiId_fkey";
-- DropForeignKey
ALTER TABLE "mii_punishments" DROP CONSTRAINT "mii_punishments_punishmentId_fkey";
-- AlterTable
ALTER TABLE "miis" DROP COLUMN "punishmentId";
-- AlterTable
ALTER TABLE "punishments" RENAME COLUMN "notes" TO "reason";
ALTER TABLE "punishments" DROP COLUMN "reasons";
-- DropTable
DROP TABLE "mii_punishments";

View file

@ -92,9 +92,6 @@ model Mii {
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
likeCount Int @default(0) likeCount Int @default(0)
punishmentId Int?
punishments MiiPunishment[]
likedBy Like[] likedBy Like[]
@@index([tags], type: Gin) @@index([tags], type: Gin)
@ -142,28 +139,13 @@ model Report {
@@map("reports") @@map("reports")
} }
model MiiPunishment {
punishmentId Int
miiId Int
reason String
punishment Punishment @relation(fields: [punishmentId], references: [id], onDelete: Cascade)
mii Mii @relation(fields: [miiId], references: [id], onDelete: Cascade)
@@id([punishmentId, miiId])
@@map("mii_punishments")
}
model Punishment { model Punishment {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
userId Int userId Int
type PunishmentType type PunishmentType
returned Boolean @default(false) returned Boolean @default(false)
notes String reason String
reasons String[]
violatingMiis MiiPunishment[]
expiresAt DateTime? expiresAt DateTime?
createdAt DateTime @default(now()) createdAt DateTime @default(now())

View file

@ -43,15 +43,6 @@ export default async function AdminPage({ searchParams }: Props) {
</div> </div>
<BannerForm /> <BannerForm />
{/* Separator */}
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium my-1">
<hr className="grow border-zinc-300" />
<span>Control Center</span>
<hr className="grow border-zinc-300" />
</div>
<ControlCenter />
<RegenerateImagesButton /> <RegenerateImagesButton />
{/* Separator */} {/* Separator */}

View file

@ -29,16 +29,7 @@ export async function GET(request: NextRequest) {
id: true, id: true,
type: true, type: true,
returned: true, returned: true,
notes: true,
reasons: true,
violatingMiis: {
select: {
miiId: true,
reason: true, reason: true,
},
},
expiresAt: true, expiresAt: true,
createdAt: true, createdAt: true,
}, },

View file

@ -14,16 +14,7 @@ const punishSchema = z.object({
.number({ error: "Duration (days) must be a number" }) .number({ error: "Duration (days) must be a number" })
.int({ error: "Duration (days) must be an integer" }) .int({ error: "Duration (days) must be an integer" })
.positive({ error: "Duration (days) must be valid" }), .positive({ error: "Duration (days) must be valid" }),
notes: z.string(),
reasons: z.array(z.string()).optional(),
miiReasons: z
.array(
z.object({
id: z.number({ error: "Mii ID must be a number" }).int({ error: "Mii ID must be an integer" }).positive({ error: "Mii ID must be valid" }),
reason: z.string(), reason: z.string(),
}),
)
.optional(),
}); });
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
@ -42,7 +33,7 @@ export async function POST(request: NextRequest) {
const parsed = punishSchema.safeParse(body); const parsed = punishSchema.safeParse(body);
if (!parsed.success) return NextResponse.json({ error: parsed.error.issues[0].message }, { status: 400 }); if (!parsed.success) return NextResponse.json({ error: parsed.error.issues[0].message }, { status: 400 });
const { type, duration, notes, reasons, miiReasons } = parsed.data; const { type, duration, reason } = parsed.data;
const expiresAt = type === "TEMP_EXILE" ? dayjs().add(duration, "days").toDate() : null; const expiresAt = type === "TEMP_EXILE" ? dayjs().add(duration, "days").toDate() : null;
@ -51,14 +42,7 @@ export async function POST(request: NextRequest) {
userId, userId,
type: type as PunishmentType, type: type as PunishmentType,
expiresAt, expiresAt,
notes, reason,
reasons: reasons?.length !== 0 ? reasons : [],
violatingMiis: {
create: miiReasons?.map((mii) => ({
miiId: mii.id,
reason: mii.reason,
})),
},
}, },
}); });

View file

@ -17,17 +17,6 @@ export async function DELETE(request: NextRequest) {
userId: Number(session.user?.id), userId: Number(session.user?.id),
returned: false, returned: false,
}, },
include: {
violatingMiis: {
include: {
mii: {
select: {
name: true,
},
},
},
},
},
}); });
if (!activePunishment) return rateLimit.sendResponse({ error: "You have no active punishments!" }, 404); if (!activePunishment) return rateLimit.sendResponse({ error: "You have no active punishments!" }, 404);

View file

@ -29,17 +29,6 @@ export default async function ExiledPage() {
userId: Number(session?.user.id), userId: Number(session?.user.id),
returned: false, returned: false,
}, },
include: {
violatingMiis: {
include: {
mii: {
select: {
name: true,
},
},
},
},
},
}); });
if (!activePunishment) redirect("/"); if (!activePunishment) redirect("/");
@ -74,36 +63,9 @@ export default async function ExiledPage() {
</p> </p>
<p className="mt-1"> <p className="mt-1">
<span className="font-bold">Note:</span> {activePunishment.notes} <span className="font-bold">Reason:</span> {activePunishment.reason}
</p> </p>
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mt-4">
<hr className="grow border-zinc-300" />
<span>Violating Items</span>
<hr className="grow border-zinc-300" />
</div>
<div className="flex flex-col gap-2 p-4">
{activePunishment.reasons.map((index, reason) => (
<div key={index} className="bg-orange-100 rounded-xl border-2 border-orange-400 p-4">
<p>
<span className="font-bold">Reason:</span> {reason}
</p>
</div>
))}
{activePunishment.violatingMiis.map((mii) => (
<div key={mii.miiId} className="bg-orange-100 rounded-xl border-2 border-orange-400 flex">
<Image src={`/mii/${mii.miiId}/image?type=mii`} alt="mii image" width={96} height={96} />
<div className="p-4">
<p className="text-xl font-bold line-clamp-1">{mii.mii.name}</p>
<p className="text-sm">
<span className="font-bold">Reason:</span> {mii.reason}
</p>
</div>
</div>
))}
</div>
<hr className="border-zinc-300 mt-2 mb-4" /> <hr className="border-zinc-300 mt-2 mb-4" />
{activePunishment.type !== "PERM_EXILE" ? ( {activePunishment.type !== "PERM_EXILE" ? (

View file

@ -5,7 +5,7 @@
import { useState } from "react"; import { useState } from "react";
import { Icon } from "@iconify/react"; import { Icon } from "@iconify/react";
import { Prisma, PunishmentType } from "@prisma/client"; import { Prisma, Punishment, PunishmentType } from "@prisma/client";
import ProfilePicture from "../profile-picture"; import ProfilePicture from "../profile-picture";
import SubmitButton from "../submit-button"; import SubmitButton from "../submit-button";
@ -16,11 +16,7 @@ interface ApiResponse {
name: string; name: string;
image: string; image: string;
createdAt: string; createdAt: string;
punishments: Prisma.PunishmentGetPayload<{ punishments: Punishment[];
include: {
violatingMiis: true;
};
}>[];
} }
interface MiiList { interface MiiList {
@ -170,7 +166,7 @@ export default function Punishments() {
</div> </div>
</div> </div>
<p className="text-sm text-zinc-600"> <p className="text-sm text-zinc-600">
<strong>Notes:</strong> {punishment.notes} <strong>Reason:</strong> {punishment.reason}
</p> </p>
{punishment.type !== "WARNING" && ( {punishment.type !== "WARNING" && (
<p className="text-sm text-zinc-600"> <p className="text-sm text-zinc-600">
@ -185,24 +181,6 @@ export default function Punishments() {
<strong>Returned:</strong> {JSON.stringify(punishment.returned)} <strong>Returned:</strong> {JSON.stringify(punishment.returned)}
</p> </p>
)} )}
<p className="text-sm text-zinc-600">
<strong>Reasons:</strong>
</p>
<ul className="ml-8 list-disc text-sm text-zinc-600">
{punishment.reasons.map((reason, index) => (
<li key={index}>{reason}</li>
))}
</ul>
<p className="text-sm text-zinc-600">
<strong>Mii Reasons:</strong>
</p>
<ul className="ml-8 list-disc text-sm text-zinc-600">
{punishment.violatingMiis.map((mii) => (
<li key={mii.miiId}>
{mii.miiId}: {mii.reason}
</li>
))}
</ul>
</div> </div>
))} ))}
</> </>