- env.ts: added 10 missing Zod-validated env vars (imager, paypal currency, argon2/bcrypt params) - Migrated 6 modules from process.env to validated env.* (auth, proxy-auth, paypal, password, redis, imager, moderation, alert, logger) - Replaced console.warn/error with pino logger in 9 server-side modules - Removed 50+ dead exports (SWF wrappers, coalesceHotelName, signIn, isStaff re-export, formatTimestamp, Skeleton/SkeletonCard, 4 unused housekeeping sections) - Consolidated date formatting: 28 files migrated to shared formatDate() from @/lib/format-date - Wired 4 radio/settings API routes through cached siteSettings service instead of raw Prisma queries - Added getMany()/getAll() helpers to SiteSettings service - Removed 88 dead Prisma model definitions (schema 2763→1846 lines) - Created admin action-helper.ts with wrapAction() for standardized error handling - Fixed useEffect dependency arrays in 4 data-heavy components - Replaced raw btn CSS classes with shadcn Button component across admin pages - Stripped dead i18n namespaces (common, pages.client) from all 22 translation files - Removed 2 dead scripts (create-release.sh, check-local-imports.ts) - Fixed knip.json configuration - Added 7 new test suites: format-date, paypal, moderation, alert, webhook, action-helper, and fixed password.test.ts for env mocking - All 358 tests passing across 72 test files - TypeScript: 0 errors
145 lines
4.1 KiB
TypeScript
145 lines
4.1 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { getTranslations } from "next-intl/server";
|
|
import { createBan, liftBan } from "@/actions/admin-bans";
|
|
import { StatusCard } from "@/components/admin/dashboard";
|
|
import { Button } from "@/components/ui/button";
|
|
import { activeBanWhere, unixNow } from "@/lib/bans";
|
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
|
import { formatDate } from "@/lib/format-date";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminBans() {
|
|
const { session, permissions } = await getAdminContext();
|
|
if (!canAccess(permissions, PERMS.BANS_VIEW, session.user.rank)) {
|
|
redirect("/admin");
|
|
}
|
|
|
|
const t = await getTranslations("pages.admin.bans");
|
|
const now = unixNow();
|
|
let bans: Awaited<ReturnType<typeof prisma.ban.findMany>> = [];
|
|
try {
|
|
bans = await prisma.ban.findMany({
|
|
where: activeBanWhere(now),
|
|
orderBy: { timestamp: "desc" },
|
|
take: 100,
|
|
});
|
|
} catch {
|
|
bans = [];
|
|
}
|
|
|
|
const permanent = bans.filter((b) => b.banExpire === 0).length;
|
|
const accountBans = bans.filter((b) => b.type === "account").length;
|
|
|
|
return (
|
|
<main>
|
|
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
|
<StatusCard
|
|
label={t("activeBans")}
|
|
value={bans.length}
|
|
state={bans.length > 0 ? "warn" : "ok"}
|
|
icon="🔨"
|
|
/>
|
|
<StatusCard
|
|
label={t("permanent")}
|
|
value={permanent}
|
|
state={permanent > 0 ? "danger" : "neutral"}
|
|
icon="⛔"
|
|
/>
|
|
<StatusCard label={t("accountBans")} value={accountBans} icon="👤" />
|
|
</div>
|
|
|
|
<form action={createBan} className="admin-card mb-6">
|
|
<h3 className="text-sm font-bold text-[var(--admin-text)] m-0 mb-3">
|
|
{t("newBan")}
|
|
</h3>
|
|
<div className="flex gap-2 flex-wrap">
|
|
<input
|
|
name="userId"
|
|
type="number"
|
|
min={1}
|
|
placeholder={t("userIdPlaceholder")}
|
|
required
|
|
/>
|
|
<select name="type">
|
|
<option value="account">{t("typeAccount")}</option>
|
|
<option value="ip">{t("typeIp")}</option>
|
|
<option value="machine">{t("typeMachine")}</option>
|
|
<option value="super">{t("typeSuper")}</option>
|
|
</select>
|
|
<input
|
|
name="hours"
|
|
type="number"
|
|
min={0}
|
|
placeholder={t("hoursPlaceholder")}
|
|
/>
|
|
<input
|
|
name="reason"
|
|
placeholder={t("reasonPlaceholder")}
|
|
className="flex-1 min-w-[160px]"
|
|
/>
|
|
<Button type="submit" variant="destructive">
|
|
{t("ban")}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
|
|
<section className="mt-6">
|
|
<h2 className="admin-section-title">
|
|
{t("activeBans")} ({bans.length})
|
|
</h2>
|
|
{bans.length === 0 ? (
|
|
<div className="admin-empty">{t("noBans")}</div>
|
|
) : (
|
|
<div className="overflow-x-auto">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>{t("colUserId")}</th>
|
|
<th>{t("colType")}</th>
|
|
<th>{t("colReason")}</th>
|
|
<th>{t("colExpires")}</th>
|
|
<th />
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{bans.map((b) => (
|
|
<tr key={b.id}>
|
|
<td>{b.userId}</td>
|
|
<td>
|
|
<span className="inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full bg-[var(--admin-accent)]/18 text-[var(--admin-text)]">
|
|
{b.type}
|
|
</span>
|
|
</td>
|
|
<td>{b.banReason || "—"}</td>
|
|
<td>
|
|
{b.banExpire === 0 ? (
|
|
<span className="inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full bg-[var(--admin-error-subtle)] text-[var(--admin-text)]">
|
|
{t("permanent")}
|
|
</span>
|
|
) : (
|
|
<span className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
|
{formatDate(new Date(b.banExpire * 1000))}
|
|
</span>
|
|
)}
|
|
</td>
|
|
<td>
|
|
<form action={liftBan}>
|
|
<input type="hidden" name="id" value={b.id} />
|
|
<Button type="submit" variant="outline">
|
|
{t("lift")}
|
|
</Button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|