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
@@ -0,0 +1,242 @@
|
||||
import { createBox, deleteBox, toggleBox, updateBox } from "@/actions/admin-writeable-boxes";
|
||||
import { StatusCard } from "@/components/admin/dashboard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export const metadata = { title: "Writeable boxes" };
|
||||
|
||||
export default async function AdminWriteableBoxes() {
|
||||
const boxes = await prisma.websiteWriteableBoxes
|
||||
.findMany({
|
||||
orderBy: [{ position: "asc" }, { id: "asc" }],
|
||||
take: 500,
|
||||
})
|
||||
.catch(() => []);
|
||||
|
||||
const activeCount = boxes.filter((b) => b.isActive).length;
|
||||
|
||||
return (
|
||||
<main>
|
||||
<section className="admin-section">
|
||||
<h2>Writeable boxes</h2>
|
||||
<p className="muted" style={{ marginTop: "-0.4rem" }}>
|
||||
Content panels stored in <code>website_writeable_boxes</code> and ordered by{" "}
|
||||
<code>position</code>. <strong>Active</strong> boxes are shown on the public home page;
|
||||
hidden ones are kept here as drafts.
|
||||
</p>
|
||||
|
||||
<div className="admin-stats">
|
||||
<StatusCard label="Total boxes" value={boxes.length} icon="🗂️" />
|
||||
<StatusCard
|
||||
label="Active"
|
||||
value={activeCount}
|
||||
state={activeCount > 0 ? "ok" : "neutral"}
|
||||
hint="shown on the public home page"
|
||||
icon="✅"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="admin-section">
|
||||
<h2>New box</h2>
|
||||
<form action={createBox} className="grid cols-2">
|
||||
<div>
|
||||
<label htmlFor="new_title" style={{ display: "block", fontWeight: 700 }}>
|
||||
Title
|
||||
</label>
|
||||
<input id="new_title" name="title" required maxLength={255} style={{ width: "100%" }} />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="new_icon" style={{ display: "block", fontWeight: 700 }}>
|
||||
Icon (emoji)
|
||||
</label>
|
||||
<input
|
||||
id="new_icon"
|
||||
name="icon"
|
||||
maxLength={255}
|
||||
placeholder="📰"
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="new_position" style={{ display: "block", fontWeight: 700 }}>
|
||||
Position
|
||||
</label>
|
||||
<input
|
||||
id="new_position"
|
||||
name="position"
|
||||
type="number"
|
||||
min={0}
|
||||
defaultValue={boxes.length}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: "flex", alignItems: "flex-end" }}>
|
||||
<label style={{ display: "flex", alignItems: "center", gap: "0.4rem", fontWeight: 700 }}>
|
||||
<input type="checkbox" name="isActive" value="1" defaultChecked /> Active
|
||||
</label>
|
||||
</div>
|
||||
<div style={{ gridColumn: "1 / -1" }}>
|
||||
<label htmlFor="new_content" style={{ display: "block", fontWeight: 700 }}>
|
||||
Content (HTML)
|
||||
</label>
|
||||
<textarea
|
||||
id="new_content"
|
||||
name="content"
|
||||
rows={5}
|
||||
style={{ width: "100%", fontFamily: "monospace" }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ gridColumn: "1 / -1", display: "flex", justifyContent: "flex-end" }}>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
+ Create box
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="admin-section">
|
||||
<h2>Boxes ({boxes.length})</h2>
|
||||
{boxes.length === 0 ? (
|
||||
<p className="muted">No writeable boxes yet.</p>
|
||||
) : (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "1.25rem" }}>
|
||||
{boxes.map((box) => (
|
||||
<div key={String(box.id)} className="card">
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.6rem",
|
||||
marginBottom: "0.75rem",
|
||||
}}
|
||||
>
|
||||
<span className="muted">#{String(box.id)}</span>
|
||||
{box.icon ? <span aria-hidden>{box.icon}</span> : null}
|
||||
<strong style={{ flex: 1 }}>{box.title}</strong>
|
||||
<span className={`admin-badge ${box.isActive ? "ok" : "danger"}`}>
|
||||
{box.isActive ? "Active" : "Hidden"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<form action={updateBox} className="grid cols-2">
|
||||
<input type="hidden" name="id" value={String(box.id)} />
|
||||
<div>
|
||||
<label
|
||||
htmlFor={`title_${box.id}`}
|
||||
style={{ display: "block", fontWeight: 700 }}
|
||||
>
|
||||
Title
|
||||
</label>
|
||||
<input
|
||||
id={`title_${box.id}`}
|
||||
name="title"
|
||||
required
|
||||
maxLength={255}
|
||||
defaultValue={box.title}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
htmlFor={`icon_${box.id}`}
|
||||
style={{ display: "block", fontWeight: 700 }}
|
||||
>
|
||||
Icon (emoji)
|
||||
</label>
|
||||
<input
|
||||
id={`icon_${box.id}`}
|
||||
name="icon"
|
||||
maxLength={255}
|
||||
defaultValue={box.icon ?? ""}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
htmlFor={`position_${box.id}`}
|
||||
style={{ display: "block", fontWeight: 700 }}
|
||||
>
|
||||
Position
|
||||
</label>
|
||||
<input
|
||||
id={`position_${box.id}`}
|
||||
name="position"
|
||||
type="number"
|
||||
min={0}
|
||||
defaultValue={box.position}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: "flex", alignItems: "flex-end" }}>
|
||||
<label
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.4rem",
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isActive"
|
||||
value="1"
|
||||
defaultChecked={box.isActive}
|
||||
/>{" "}
|
||||
Active
|
||||
</label>
|
||||
</div>
|
||||
<div style={{ gridColumn: "1 / -1" }}>
|
||||
<label
|
||||
htmlFor={`content_${box.id}`}
|
||||
style={{ display: "block", fontWeight: 700 }}
|
||||
>
|
||||
Content (HTML)
|
||||
</label>
|
||||
<textarea
|
||||
id={`content_${box.id}`}
|
||||
name="content"
|
||||
rows={5}
|
||||
defaultValue={box.content}
|
||||
style={{ width: "100%", fontFamily: "monospace" }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ gridColumn: "1 / -1", display: "flex", justifyContent: "flex-end" }}>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "0.5rem",
|
||||
marginTop: "0.75rem",
|
||||
paddingTop: "0.75rem",
|
||||
borderTop: "1px solid rgba(255,255,255,0.08)",
|
||||
}}
|
||||
>
|
||||
<form action={toggleBox}>
|
||||
<input type="hidden" name="id" value={String(box.id)} />
|
||||
<input type="hidden" name="next" value={box.isActive ? "0" : "1"} />
|
||||
<button type="submit" className="btn">
|
||||
{box.isActive ? "Hide" : "Activate"}
|
||||
</button>
|
||||
</form>
|
||||
<form action={deleteBox}>
|
||||
<input type="hidden" name="id" value={String(box.id)} />
|
||||
<button type="submit" className="btn btn-danger">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user