- Remove .prettierrc (dead config, Biome replaces Prettier) - Rename lighthouserc.json to lighthouserc.cjs with module.exports for ESM compat - Add logger.warn to empty catch blocks in auth, register, site-settings, prisma-cache, redis, security, rate-limit - Unify ActionResult type: action-helper.ts uses 'ok' consistent with safe-action-shared.ts - Add noUnusedLocals + noUnusedParameters to tsconfig + fix 25 pre-existing unused vars - Replace barrel export src/types/index.ts with direct @/types/common imports - Make trustHost conditional (development only) in auth.ts - Add pre-flight URL validation to update-Nitrov3.sh to catch image.library.url misconfigurations - Improve NITRO_IMAGE_LIBRARY_URL content validation in pre-flight & post-compute checks
207 lines
5.4 KiB
TypeScript
207 lines
5.4 KiB
TypeScript
import Link from "next/link";
|
|
import { redirect } from "next/navigation";
|
|
import { getTranslations } from "next-intl/server";
|
|
import { AdminSimplePager } from "@/components/admin/admin-simple-pager";
|
|
import { StatusCard } from "@/components/admin/dashboard";
|
|
import { Button } from "@/components/ui/button";
|
|
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
|
|
import { formatDate } from "@/lib/format-date";
|
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function AdminGuildsPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<Record<string, string>>;
|
|
}) {
|
|
const { session, permissions } = await getAdminContext();
|
|
if (!canAccess(permissions, PERMS.USERS_VIEW, session.user.rank)) {
|
|
redirect("/admin");
|
|
}
|
|
|
|
const t = await getTranslations("pages.admin.guilds");
|
|
const raw = await searchParams;
|
|
const parsed = parseListParams(new URLSearchParams(raw));
|
|
const q = parsed.search.trim();
|
|
|
|
let total = 0;
|
|
let rows: Array<{
|
|
id: number;
|
|
name: string;
|
|
description: string;
|
|
userId: number;
|
|
badge: string;
|
|
dateCreated: number;
|
|
roomId: number;
|
|
}> = [];
|
|
let loadError = false;
|
|
|
|
try {
|
|
const where = q
|
|
? {
|
|
OR: [
|
|
{ name: { contains: q } },
|
|
{ description: { contains: q } },
|
|
...(Number.isFinite(Number(q)) && Number(q) > 0
|
|
? [{ id: Number(q) }]
|
|
: []),
|
|
],
|
|
}
|
|
: {};
|
|
|
|
total = await prisma.guilds.count({ where });
|
|
const pagination = calcPagination(total, parsed.page, parsed.perPage);
|
|
rows = await prisma.guilds.findMany({
|
|
where,
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
description: true,
|
|
userId: true,
|
|
badge: true,
|
|
dateCreated: true,
|
|
roomId: true,
|
|
},
|
|
orderBy: { id: "desc" },
|
|
skip: pagination.offset,
|
|
take: pagination.perPage,
|
|
});
|
|
} catch {
|
|
loadError = true;
|
|
}
|
|
|
|
const pagination = calcPagination(total, parsed.page, parsed.perPage);
|
|
const ownerIds = [
|
|
...new Set(rows.map((r) => r.userId).filter((id) => id > 0)),
|
|
];
|
|
const guildIds = rows.map((r) => r.id);
|
|
|
|
const [owners, memberGroups] = await Promise.all([
|
|
ownerIds.length
|
|
? prisma.user
|
|
.findMany({
|
|
where: { id: { in: ownerIds } },
|
|
select: { id: true, username: true },
|
|
})
|
|
.catch(() => [])
|
|
: Promise.resolve([]),
|
|
guildIds.length
|
|
? prisma.guildsMembers
|
|
.groupBy({
|
|
by: ["guildId"],
|
|
where: { guildId: { in: guildIds } },
|
|
_count: { _all: true },
|
|
})
|
|
.catch(() => [])
|
|
: Promise.resolve([]),
|
|
]);
|
|
|
|
const ownerById = new Map(owners.map((u) => [u.id, u.username]));
|
|
const membersByGuild = new Map(
|
|
memberGroups.map((g) => [g.guildId, g._count._all]),
|
|
);
|
|
|
|
return (
|
|
<main>
|
|
{loadError ? (
|
|
<div className="mb-4 rounded-lg bg-[var(--admin-error-subtle)] p-3 text-xs text-[var(--admin-error)]">
|
|
{t("loadError")}
|
|
</div>
|
|
) : null}
|
|
|
|
<form className="mb-4 flex gap-2" method="get">
|
|
<input
|
|
type="search"
|
|
name="search"
|
|
defaultValue={q}
|
|
placeholder={t("searchPlaceholder")}
|
|
className="admin-input flex-1"
|
|
/>
|
|
<Button type="submit" variant="default" size="sm">
|
|
{t("search")}
|
|
</Button>
|
|
</form>
|
|
|
|
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
|
<StatusCard label={t("totalGuilds")} value={total} icon="🛡️" />
|
|
</div>
|
|
|
|
<section>
|
|
<h2 className="admin-section-title">
|
|
{t("title")} ({total})
|
|
</h2>
|
|
{rows.length === 0 ? (
|
|
<div className="admin-empty">{t("empty")}</div>
|
|
) : (
|
|
<div className="admin-card overflow-x-auto" style={{ padding: 0 }}>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>{t("colId")}</th>
|
|
<th>{t("colBadge")}</th>
|
|
<th>{t("colName")}</th>
|
|
<th>{t("colOwner")}</th>
|
|
<th>{t("colMembers")}</th>
|
|
<th>{t("colCreated")}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{rows.map((g) => (
|
|
<tr key={g.id}>
|
|
<td className="muted">{g.id}</td>
|
|
<td>
|
|
{g.badge ? (
|
|
// eslint-disable-next-line @next/next/no-img-element
|
|
<img
|
|
src={`https://habbo-stories-content.s3.amazonaws.com/badge-part-images/${g.badge}.gif`}
|
|
alt=""
|
|
width={40}
|
|
height={40}
|
|
className="h-10 w-10 object-contain"
|
|
/>
|
|
) : (
|
|
<span className="muted">—</span>
|
|
)}
|
|
</td>
|
|
<td>
|
|
<Link
|
|
href={`/admin/guilds/${g.id}`}
|
|
className="font-medium hover:underline"
|
|
>
|
|
{g.name || `#${g.id}`}
|
|
</Link>
|
|
{g.description ? (
|
|
<div className="muted text-xs line-clamp-1 max-w-xs">
|
|
{g.description}
|
|
</div>
|
|
) : null}
|
|
</td>
|
|
<td>
|
|
<Link href={`/admin/users/show/${g.userId}`}>
|
|
{ownerById.get(g.userId) ?? `#${g.userId}`}
|
|
</Link>
|
|
</td>
|
|
<td>{membersByGuild.get(g.id) ?? 0}</td>
|
|
<td className="muted">
|
|
{formatDate(new Date(g.dateCreated * 1000), "date")}
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
<AdminSimplePager
|
|
page={pagination.page}
|
|
lastPage={pagination.lastPage}
|
|
total={total}
|
|
basePath="/admin/guilds"
|
|
params={q ? { search: q } : undefined}
|
|
/>
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|