Built via two parallel agent workflows reading the real Prisma schema, then integrated + verified. Public: /shop (categories + storefront), /community hub, /rankings (top by credits), /staff, /photos (camera_web gallery), /help (categories + rules), /help/tickets (auth-gated user tickets + create), /settings (auth-gated, update motto via RCON). Admin: /admin/catalog (+[id] items), /admin/radio (shouts/apps/schedules + delete shout), /admin/teams (CRUD), /admin/permissions (read), /admin/wordfilter (CRUD + RCON push), /admin/ip (whitelist/blacklist CRUD), /admin/applications (list + dismiss), /admin/logs (chat/command/alert read), /admin/achievements (read). Server actions all staff-gated. Header + admin nav extended. Verified: tsc exit 0, vitest 48/48, next build exit 0 (33 routes); curl-probed every route — public 200/<main>, auth+admin correctly 307-redirect when unauthorized.
177 lines
5.0 KiB
TypeScript
177 lines
5.0 KiB
TypeScript
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
// chatlogs_room and commandlogs are @@ignore'd in the schema (no PK), so Prisma
|
|
// generates no delegate for them — they are read via $queryRaw against the real
|
|
// emulator columns. alert_logs has a proper delegate (prisma.alertLogs).
|
|
|
|
type ChatlogRoomRow = {
|
|
room_id: number;
|
|
user_from_id: number;
|
|
user_to_id: number;
|
|
message: string;
|
|
timestamp: number;
|
|
};
|
|
|
|
type CommandlogRow = {
|
|
user_id: number;
|
|
timestamp: number;
|
|
command: string;
|
|
params: string;
|
|
succes: string;
|
|
};
|
|
|
|
function fromUnix(ts: number | null | undefined): string {
|
|
if (!ts || Number(ts) <= 0) return "—";
|
|
return new Date(Number(ts) * 1000)
|
|
.toISOString()
|
|
.slice(0, 16)
|
|
.replace("T", " ");
|
|
}
|
|
|
|
function fromDate(d: Date | null | undefined): string {
|
|
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "—";
|
|
}
|
|
|
|
export default async function AdminLogs() {
|
|
let chatlogs: ChatlogRoomRow[] = [];
|
|
try {
|
|
chatlogs = await prisma.$queryRaw<ChatlogRoomRow[]>`
|
|
SELECT room_id, user_from_id, user_to_id, message, timestamp
|
|
FROM chatlogs_room
|
|
ORDER BY timestamp DESC
|
|
LIMIT 50
|
|
`;
|
|
} catch {
|
|
chatlogs = [];
|
|
}
|
|
|
|
let commandlogs: CommandlogRow[] = [];
|
|
try {
|
|
commandlogs = await prisma.$queryRaw<CommandlogRow[]>`
|
|
SELECT user_id, timestamp, command, params, succes
|
|
FROM commandlogs
|
|
ORDER BY timestamp DESC
|
|
LIMIT 50
|
|
`;
|
|
} catch {
|
|
commandlogs = [];
|
|
}
|
|
|
|
let alertLogs: Awaited<ReturnType<typeof prisma.alertLogs.findMany>> = [];
|
|
try {
|
|
alertLogs = await prisma.alertLogs.findMany({
|
|
orderBy: { id: "desc" },
|
|
take: 50,
|
|
});
|
|
} catch {
|
|
alertLogs = [];
|
|
}
|
|
|
|
return (
|
|
<main>
|
|
<h1>Logs</h1>
|
|
<p className="muted" style={{ marginTop: "-0.4rem" }}>
|
|
Read-only · 50 most recent of each.
|
|
</p>
|
|
|
|
<section className="card" style={{ marginBottom: "1.5rem" }}>
|
|
<h3 style={{ marginTop: 0 }}>Room chat ({chatlogs.length})</h3>
|
|
{chatlogs.length === 0 ? (
|
|
<p className="muted">No room chat logs.</p>
|
|
) : (
|
|
<div style={{ overflowX: "auto" }}>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>When</th>
|
|
<th>Room</th>
|
|
<th>From</th>
|
|
<th>To</th>
|
|
<th>Message</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{chatlogs.map((c, i) => (
|
|
<tr key={`${c.timestamp}-${c.user_from_id}-${i}`}>
|
|
<td className="muted">{fromUnix(c.timestamp)}</td>
|
|
<td>{String(c.room_id)}</td>
|
|
<td>{String(c.user_from_id)}</td>
|
|
<td>{c.user_to_id ? String(c.user_to_id) : "—"}</td>
|
|
<td>{c.message}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</section>
|
|
|
|
<section className="card" style={{ marginBottom: "1.5rem" }}>
|
|
<h3 style={{ marginTop: 0 }}>Commands ({commandlogs.length})</h3>
|
|
{commandlogs.length === 0 ? (
|
|
<p className="muted">No command logs.</p>
|
|
) : (
|
|
<div style={{ overflowX: "auto" }}>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>When</th>
|
|
<th>User</th>
|
|
<th>Command</th>
|
|
<th>Params</th>
|
|
<th>OK</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{commandlogs.map((c, i) => (
|
|
<tr key={`${c.timestamp}-${c.user_id}-${i}`}>
|
|
<td className="muted">{fromUnix(c.timestamp)}</td>
|
|
<td>{String(c.user_id)}</td>
|
|
<td>{c.command}</td>
|
|
<td className="muted">{c.params}</td>
|
|
<td>{c.succes === "yes" ? "✓" : "✗"}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</section>
|
|
|
|
<section className="card">
|
|
<h3 style={{ marginTop: 0 }}>Alerts ({alertLogs.length})</h3>
|
|
{alertLogs.length === 0 ? (
|
|
<p className="muted">No alert logs.</p>
|
|
) : (
|
|
<div style={{ overflowX: "auto" }}>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>When</th>
|
|
<th>Type</th>
|
|
<th>Severity</th>
|
|
<th>Message</th>
|
|
<th>Read</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{alertLogs.map((a) => (
|
|
<tr key={String(a.id)}>
|
|
<td className="muted">{fromDate(a.createdAt)}</td>
|
|
<td>{a.type}</td>
|
|
<td>{a.severity}</td>
|
|
<td>{a.message}</td>
|
|
<td>{a.isRead ? "✓" : "○"}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|