Fill the remaining gaps: badge upload, radio tools, VPN, writeable boxes
Built the admin tools previously listed as missing: - Badge upload (/admin/badges): uploads a <code>.gif into the emulator's badge dir via BADGE_UPLOAD_DIR (node:fs); validated code/type/size, logged. Made configurable rather than skipped. - Radio tools: /admin/radio/api-keys (CRUD, server-generated keys), /admin/radio/autodj (Auto-DJ playlist CRUD), /admin/radio/embed (embed snippet generator), /admin/radio/points (points settings), /admin/radio/monitoring (live stream/now-playing/listeners status). radio_api_keys + radio_auto_dj_playlist already had real columns. - /admin/vpn: VPN/proxy detection config (block toggle + provider + key), complementing /admin/ip's raw blacklist. - Writeable boxes: new website_writeable_boxes table (model + migration 0006) + /admin/writeable-boxes CRUD; active boxes render on the public home page. env: BADGE_UPLOAD_DIR. Verified live (prod, amx_test): all 8 pages render with real data; a test writeable box appeared on the public home and was reverted. tsc 0, vitest 49/49, next build 0 (7 new admin routes).
This commit is contained in:
1 parent
e004dfedaf
commit
0cd4d06ff6
21 files changed
+2443
-61
No files matched your search
+128
-61
@@ -1,9 +1,18 @@
|
||||
import { giveBadge } from "@/actions/admin-badges";
|
||||
import { uploadBadge } from "@/actions/admin-badge-upload";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminBadges() {
|
||||
export const metadata = { title: "Badges" };
|
||||
|
||||
export default async function AdminBadges({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ uploaded?: string; error?: string }>;
|
||||
}) {
|
||||
const { uploaded, error } = await searchParams;
|
||||
|
||||
let badges: Awaited<ReturnType<typeof prisma.websiteBadges.findMany>> = [];
|
||||
try {
|
||||
badges = await prisma.websiteBadges.findMany({
|
||||
@@ -16,68 +25,126 @@ export default async function AdminBadges() {
|
||||
|
||||
return (
|
||||
<main>
|
||||
<h1>Badges</h1>
|
||||
<p className="muted">
|
||||
Website badge catalogue (<code>website_badges</code>). Granting fires the emulator
|
||||
<code> givebadge</code> RCON command and records the badge in <code>users_badges</code>.
|
||||
</p>
|
||||
<section className="admin-section">
|
||||
<h2>Badges</h2>
|
||||
<p className="muted">
|
||||
Website badge catalogue (<code>website_badges</code>). Granting fires the emulator
|
||||
<code> givebadge</code> RCON command and records the badge in <code>users_badges</code>.
|
||||
</p>
|
||||
|
||||
<form action={giveBadge} className="card" style={{ marginBottom: "1.5rem" }}>
|
||||
<h3 style={{ marginTop: 0 }}>Give badge to user</h3>
|
||||
<div style={{ display: "flex", gap: "0.5rem", flexWrap: "wrap", alignItems: "center" }}>
|
||||
<input name="userId" type="number" min={1} placeholder="User ID" required />
|
||||
<input
|
||||
name="code"
|
||||
placeholder="Badge code (e.g. ADM)"
|
||||
required
|
||||
maxLength={32}
|
||||
style={{ flex: 1, minWidth: 160 }}
|
||||
list="badge-codes"
|
||||
/>
|
||||
<datalist id="badge-codes">
|
||||
{badges.map((b) => (
|
||||
<option key={String(b.id)} value={b.badgeKey}>
|
||||
{b.badgeName}
|
||||
</option>
|
||||
))}
|
||||
</datalist>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Give badge
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{uploaded ? (
|
||||
<p>
|
||||
<span className="admin-badge ok">Uploaded</span> Badge image{" "}
|
||||
<code>{uploaded}.gif</code> saved.
|
||||
</p>
|
||||
) : null}
|
||||
{error ? (
|
||||
<p>
|
||||
<span className="admin-badge danger">Error</span> {error}
|
||||
</p>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Code</th>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{badges.map((b) => (
|
||||
<tr key={String(b.id)}>
|
||||
<td>
|
||||
<code>{b.badgeKey}</code>
|
||||
</td>
|
||||
<td>{b.badgeName}</td>
|
||||
<td className="muted">{b.badgeDescription}</td>
|
||||
<td>
|
||||
<form action={giveBadge} style={{ display: "flex", gap: "0.4rem", alignItems: "center" }}>
|
||||
<input type="hidden" name="code" value={b.badgeKey} />
|
||||
<input name="userId" type="number" min={1} placeholder="User ID" required style={{ width: 90 }} />
|
||||
<button type="submit" className="btn btn-outline">
|
||||
Give
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{badges.length === 0 ? <p className="muted">No badges in the catalogue.</p> : null}
|
||||
<section className="admin-section">
|
||||
<h2>Upload badge image</h2>
|
||||
<p className="muted" style={{ marginTop: "-0.4rem" }}>
|
||||
Saves a <code>.gif</code> badge image to the emulator badge directory
|
||||
(<code>BADGE_UPLOAD_DIR</code>). The file is stored as <code><code>.gif</code>.
|
||||
</p>
|
||||
<form action={uploadBadge} className="card">
|
||||
<div style={{ display: "flex", gap: "0.5rem", flexWrap: "wrap", alignItems: "center" }}>
|
||||
<input type="file" name="file" accept=".gif,.png" required />
|
||||
<input
|
||||
name="code"
|
||||
placeholder="Badge code (e.g. ADM)"
|
||||
required
|
||||
maxLength={64}
|
||||
pattern="[A-Za-z0-9_-]{1,64}"
|
||||
style={{ flex: 1, minWidth: 160 }}
|
||||
/>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Upload
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="admin-section">
|
||||
<h2>Give badge to user</h2>
|
||||
<form action={giveBadge} className="card">
|
||||
<div style={{ display: "flex", gap: "0.5rem", flexWrap: "wrap", alignItems: "center" }}>
|
||||
<input name="userId" type="number" min={1} placeholder="User ID" required />
|
||||
<input
|
||||
name="code"
|
||||
placeholder="Badge code (e.g. ADM)"
|
||||
required
|
||||
maxLength={32}
|
||||
style={{ flex: 1, minWidth: 160 }}
|
||||
list="badge-codes"
|
||||
/>
|
||||
<datalist id="badge-codes">
|
||||
{badges.map((b) => (
|
||||
<option key={String(b.id)} value={b.badgeKey}>
|
||||
{b.badgeName}
|
||||
</option>
|
||||
))}
|
||||
</datalist>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Give badge
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="admin-section">
|
||||
<h2>Catalogue ({badges.length})</h2>
|
||||
{badges.length === 0 ? (
|
||||
<p className="muted">No badges in the catalogue.</p>
|
||||
) : (
|
||||
<div style={{ overflowX: "auto" }}>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Code</th>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{badges.map((b) => (
|
||||
<tr key={String(b.id)}>
|
||||
<td>
|
||||
<code>{b.badgeKey}</code>
|
||||
</td>
|
||||
<td>{b.badgeName}</td>
|
||||
<td className="muted">{b.badgeDescription}</td>
|
||||
<td>
|
||||
<form
|
||||
action={giveBadge}
|
||||
style={{ display: "flex", gap: "0.4rem", alignItems: "center" }}
|
||||
>
|
||||
<input type="hidden" name="code" value={b.badgeKey} />
|
||||
<input
|
||||
name="userId"
|
||||
type="number"
|
||||
min={1}
|
||||
placeholder="User ID"
|
||||
required
|
||||
style={{ width: 90 }}
|
||||
/>
|
||||
<button type="submit" className="btn btn-outline">
|
||||
Give
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user