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,222 @@
|
||||
import Link from "next/link";
|
||||
import { savePoints } from "@/actions/admin-radio-points";
|
||||
import { StatusCard } from "@/components/admin/dashboard";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export const metadata = { title: "Radio Points" };
|
||||
|
||||
// Defaults used when the website_settings rows are missing OR the DB is
|
||||
// unreachable, so the editor still renders in local dev.
|
||||
const DEFAULTS = {
|
||||
radio_points_enabled: "0",
|
||||
radio_points_per_minute: "1",
|
||||
radio_points_currency: "credits",
|
||||
radio_points_max_per_day: "0",
|
||||
radio_points_min_listeners: "0",
|
||||
} as const;
|
||||
|
||||
const CURRENCIES = ["credits", "duckets", "diamonds", "points"] as const;
|
||||
|
||||
export default async function AdminRadioPointsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ saved?: string }>;
|
||||
}) {
|
||||
const { saved } = await searchParams;
|
||||
|
||||
// Read current values with siteSettings.get(defaults); fall back to DEFAULTS
|
||||
// on any read error so select()-typed values stay strings.
|
||||
const values = {
|
||||
radio_points_enabled: await siteSettings
|
||||
.get("radio_points_enabled", DEFAULTS.radio_points_enabled)
|
||||
.catch(() => DEFAULTS.radio_points_enabled),
|
||||
radio_points_per_minute: await siteSettings
|
||||
.get("radio_points_per_minute", DEFAULTS.radio_points_per_minute)
|
||||
.catch(() => DEFAULTS.radio_points_per_minute),
|
||||
radio_points_currency: await siteSettings
|
||||
.get("radio_points_currency", DEFAULTS.radio_points_currency)
|
||||
.catch(() => DEFAULTS.radio_points_currency),
|
||||
radio_points_max_per_day: await siteSettings
|
||||
.get("radio_points_max_per_day", DEFAULTS.radio_points_max_per_day)
|
||||
.catch(() => DEFAULTS.radio_points_max_per_day),
|
||||
radio_points_min_listeners: await siteSettings
|
||||
.get("radio_points_min_listeners", DEFAULTS.radio_points_min_listeners)
|
||||
.catch(() => DEFAULTS.radio_points_min_listeners),
|
||||
};
|
||||
|
||||
const enabled = (values.radio_points_enabled ?? "0") === "1";
|
||||
const perMinute = values.radio_points_per_minute ?? DEFAULTS.radio_points_per_minute;
|
||||
const currency = (values.radio_points_currency ?? DEFAULTS.radio_points_currency) as string;
|
||||
const maxPerDay = values.radio_points_max_per_day ?? DEFAULTS.radio_points_max_per_day;
|
||||
const minListeners = values.radio_points_min_listeners ?? DEFAULTS.radio_points_min_listeners;
|
||||
const selectedCurrency = CURRENCIES.includes(currency as (typeof CURRENCIES)[number])
|
||||
? currency
|
||||
: "credits";
|
||||
|
||||
return (
|
||||
<main>
|
||||
<nav className="muted" style={{ marginBottom: "0.5rem" }}>
|
||||
<Link href="/admin/radio">Radio</Link> ·{" "}
|
||||
<Link href="/admin/radio/settings">Settings</Link> ·{" "}
|
||||
<Link href="/admin/radio/points">Points</Link> ·{" "}
|
||||
<Link href="/admin/radio/banners">Banners</Link> ·{" "}
|
||||
<Link href="/admin/radio/ranks">Ranks</Link> ·{" "}
|
||||
<Link href="/admin/radio/history">History</Link>
|
||||
</nav>
|
||||
|
||||
<section className="admin-section">
|
||||
<h2>Radio Listener Points</h2>
|
||||
<p className="muted" style={{ marginTop: "-0.4rem" }}>
|
||||
Reward listeners with currency for time spent on the radio. Edits write
|
||||
to <code>website_settings</code> (<code>radio_points_*</code> keys) and
|
||||
bust the runtime settings cache. Booleans use <code>0</code> /{" "}
|
||||
<code>1</code>.
|
||||
</p>
|
||||
|
||||
{saved === "1" ? (
|
||||
<p>
|
||||
<span className="admin-badge ok">Saved</span>
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="admin-stats">
|
||||
<StatusCard
|
||||
label="Points"
|
||||
value={enabled ? "Enabled" : "Disabled"}
|
||||
state={enabled ? "ok" : "danger"}
|
||||
icon="🎧"
|
||||
/>
|
||||
<StatusCard
|
||||
label="Per minute"
|
||||
value={perMinute}
|
||||
hint={`paid in ${selectedCurrency}`}
|
||||
icon="⏱️"
|
||||
/>
|
||||
<StatusCard
|
||||
label="Max / day"
|
||||
value={maxPerDay === "0" ? "Unlimited" : maxPerDay}
|
||||
icon="📈"
|
||||
/>
|
||||
<StatusCard label="Min listeners" value={minListeners} icon="👥" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="admin-section">
|
||||
<h2>Settings</h2>
|
||||
<form action={savePoints}>
|
||||
<div className="grid cols-2">
|
||||
<div>
|
||||
<label htmlFor="radio_points_enabled" style={{ display: "block", fontWeight: 700 }}>
|
||||
Points enabled
|
||||
</label>
|
||||
<select
|
||||
id="radio_points_enabled"
|
||||
name="radio_points_enabled"
|
||||
defaultValue={enabled ? "1" : "0"}
|
||||
style={{ width: "100%" }}
|
||||
>
|
||||
<option value="1">Enabled</option>
|
||||
<option value="0">Disabled</option>
|
||||
</select>
|
||||
<p className="muted" style={{ margin: "0.2rem 0 0" }}>
|
||||
Master switch for awarding listener points.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="radio_points_currency" style={{ display: "block", fontWeight: 700 }}>
|
||||
Currency
|
||||
</label>
|
||||
<select
|
||||
id="radio_points_currency"
|
||||
name="radio_points_currency"
|
||||
defaultValue={selectedCurrency}
|
||||
style={{ width: "100%" }}
|
||||
>
|
||||
{CURRENCIES.map((c) => (
|
||||
<option key={c} value={c}>
|
||||
{c.charAt(0).toUpperCase() + c.slice(1)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<p className="muted" style={{ margin: "0.2rem 0 0" }}>
|
||||
Which wallet the points are paid into.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
htmlFor="radio_points_per_minute"
|
||||
style={{ display: "block", fontWeight: 700 }}
|
||||
>
|
||||
Points per minute
|
||||
</label>
|
||||
<input
|
||||
id="radio_points_per_minute"
|
||||
name="radio_points_per_minute"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
defaultValue={perMinute}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
<p className="muted" style={{ margin: "0.2rem 0 0" }}>
|
||||
Amount awarded for each full minute of listening.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
htmlFor="radio_points_max_per_day"
|
||||
style={{ display: "block", fontWeight: 700 }}
|
||||
>
|
||||
Max points per day
|
||||
</label>
|
||||
<input
|
||||
id="radio_points_max_per_day"
|
||||
name="radio_points_max_per_day"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
defaultValue={maxPerDay}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
<p className="muted" style={{ margin: "0.2rem 0 0" }}>
|
||||
Daily cap per user. Use <code>0</code> for unlimited.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
htmlFor="radio_points_min_listeners"
|
||||
style={{ display: "block", fontWeight: 700 }}
|
||||
>
|
||||
Minimum listeners
|
||||
</label>
|
||||
<input
|
||||
id="radio_points_min_listeners"
|
||||
name="radio_points_min_listeners"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
defaultValue={minListeners}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
<p className="muted" style={{ margin: "0.2rem 0 0" }}>
|
||||
Points are only awarded when at least this many people are tuned in.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "flex", justifyContent: "flex-end", marginTop: "1rem" }}>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save points settings
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user