Files
EpicNext-Cms/src/app/(site)/banned/page.tsx
T
openhands 51ef7602ca perf: migrate pages to Cache Components via root layout opt-out
Remove the per-route 'export const instant = false' opt-outs now that the root layout carries the single Cache Components opt-out. Child pages inherit the opt-out, so admin/mod/radio leaf pages that only access cached or DB data stay instant while runtime-dependent pages remain dynamic. Update the staff-smoke contract test to assert the root-layout contract.
2026-08-07 18:51:45 +02:00

71 lines
1.7 KiB
TypeScript

import { and, desc, eq, gt, or } from "drizzle-orm";
import { getTranslations } from "next-intl/server";
import { ContentCard } from "@/components/public/ui";
import { auth } from "@/lib/auth";
import { unixNow } from "@/lib/bans";
import { Ban, db } from "@/lib/db";
const FAR_FUTURE = Math.floor(Date.now() / 1000) + 50 * 365 * 24 * 3600;
export default async function BannedPage() {
const t = await getTranslations("pages.banned");
const session = await auth();
let reason = "";
let expire = 0;
let hasBan = false;
if (session?.user?.id) {
try {
const now = unixNow();
const [ban] = await db
.select({
banReason: Ban.banReason,
banExpire: Ban.banExpire,
})
.from(Ban)
.where(
and(
eq(Ban.userId, Number(session.user.id)),
or(eq(Ban.banExpire, 0), gt(Ban.banExpire, now)),
),
)
.orderBy(desc(Ban.timestamp))
.limit(1);
if (ban) {
hasBan = true;
reason = ban.banReason;
expire = ban.banExpire;
}
} catch {
// show generic message
}
}
const expiryText = !hasBan
? ""
: expire === 0 || expire > FAR_FUTURE
? t("permanent")
: t("expires", {
date: new Date(expire * 1000)
.toISOString()
.slice(0, 16)
.replace("T", " "),
});
return (
<main style={{ maxWidth: 560, margin: "2rem auto" }}>
<ContentCard icon="🚫" title={t("title")} subtitle={t("subtitle")}>
<p style={{ marginTop: 0 }}>{t("body")}</p>
{reason ? (
<p>
<strong>{t("reasonLabel")}</strong> {reason}
</p>
) : null}
{expiryText ? <p className="muted">{expiryText}</p> : null}
<p className="muted" style={{ marginBottom: 0 }}>
{t("contactStaff")}
</p>
</ContentCard>
</main>
);
}