Add security middleware, audit log, alerts, PayPal, cron, radio + apps
Security (launch blockers): - src/middleware.ts (edge): forwards x-pathname + real client IP. - access-guard.ts (Node, from root layout): routes non-staff to /maintenance when maintenance mode is on, banned users to /banned. New /banned + /maintenance pages (the consumers the admin toggle was missing). Admin layout enforces force_staff_2fa before /admin. - staff-activity.ts audit log wired into ban/lift/give-currency/set-rank actions. Infra (parallel agents): alert service (alert_logs + Discord embed + email), PayPal top-up (create/capture API routes + /shop/topup), cron worker (scripts/jobs-worker.ts via croner: emulator-ping->alert, maintenance-check, bans-cleanup), social connections page, admin radio settings/banners/ranks. Public radio subsystem: /radio (+schedule, shouts+post, contests, giveaways, apply, leaderboard) and /apply/staff + /apply/team submission forms. Radio nav link added. .env.example documents the new optional vars. (radio song-requests dropped: its table is a stub in AtomCMS — columns added by un-modeled alter-migrations.) Verified: tsc exit 0, vitest 48/48, next build exit 0 (82 page routes).
This commit is contained in:
1 parent
e19debb795
commit
22d53d0e9c
40 files changed
+3781
-6
No files matched your search
@@ -1,12 +1,23 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import type { ReactNode } from "react";
|
||||
import { requireStaff } from "@/lib/admin/guard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdminLayout({ children }: { children: ReactNode }) {
|
||||
const staff = await requireStaff();
|
||||
|
||||
// Force staff 2FA before the admin panel (AtomCMS ForceStaffTwoFactorMiddleware).
|
||||
if (await siteSettings.getBool("force_staff_2fa", false)) {
|
||||
const u = await prisma.user
|
||||
.findUnique({ where: { id: staff.id }, select: { twoFactorConfirmedAt: true } })
|
||||
.catch(() => null);
|
||||
if (!u?.twoFactorConfirmedAt) redirect("/settings/2fa?error=staffrequired");
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ display: "grid", gridTemplateColumns: "190px 1fr", gap: "1.5rem" }}>
|
||||
<aside className="card" style={{ height: "fit-content" }}>
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
import Link from 'next/link';
|
||||
import {
|
||||
createRadioBanner,
|
||||
deleteRadioBanner,
|
||||
updateRadioBanner,
|
||||
} from '@/actions/admin-radio-extra';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
type Banner = {
|
||||
id: bigint;
|
||||
userId: bigint;
|
||||
imagePath: string;
|
||||
title: string | null;
|
||||
description: string | null;
|
||||
sortOrder: number;
|
||||
isActive: boolean;
|
||||
createdAt: Date | null;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace('T', ' ') : '—';
|
||||
}
|
||||
|
||||
export default async function AdminRadioBannersPage() {
|
||||
let banners: Banner[] = [];
|
||||
let dbError = false;
|
||||
|
||||
try {
|
||||
banners = await prisma.radioBanners.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
imagePath: true,
|
||||
title: true,
|
||||
description: true,
|
||||
sortOrder: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
},
|
||||
orderBy: [{ sortOrder: 'asc' }, { id: 'asc' }],
|
||||
});
|
||||
} catch {
|
||||
dbError = true;
|
||||
banners = [];
|
||||
}
|
||||
|
||||
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/banners">Banners</Link> ·{' '}
|
||||
<Link href="/admin/radio/ranks">Ranks</Link>
|
||||
</nav>
|
||||
|
||||
<h1>Radio Banners</h1>
|
||||
<p className="muted">
|
||||
Promotional banners shown on the radio page, ordered by sort order.
|
||||
</p>
|
||||
|
||||
{dbError ? (
|
||||
<div className="card" style={{ marginBottom: '1.5rem' }}>
|
||||
<p className="muted" style={{ margin: 0 }}>
|
||||
Could not load banners (database unavailable).
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<form action={createRadioBanner} className="card" style={{ marginBottom: '1.5rem' }}>
|
||||
<h3 style={{ marginTop: 0 }}>Add banner</h3>
|
||||
<div className="grid cols-2">
|
||||
<div>
|
||||
<label htmlFor="new_imagePath" style={{ display: 'block', fontWeight: 700 }}>
|
||||
Image path / URL
|
||||
</label>
|
||||
<input
|
||||
id="new_imagePath"
|
||||
name="imagePath"
|
||||
placeholder="/storage/radio/banner.png"
|
||||
required
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="new_title" style={{ display: 'block', fontWeight: 700 }}>
|
||||
Title
|
||||
</label>
|
||||
<input id="new_title" name="title" style={{ width: '100%' }} />
|
||||
</div>
|
||||
<div style={{ gridColumn: '1 / -1' }}>
|
||||
<label htmlFor="new_description" style={{ display: 'block', fontWeight: 700 }}>
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
id="new_description"
|
||||
name="description"
|
||||
rows={2}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="new_sortOrder" style={{ display: 'block', fontWeight: 700 }}>
|
||||
Sort order
|
||||
</label>
|
||||
<input
|
||||
id="new_sortOrder"
|
||||
name="sortOrder"
|
||||
type="number"
|
||||
defaultValue={0}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'flex-end' }}>
|
||||
<label style={{ display: 'inline-flex', gap: '0.4rem', alignItems: 'center' }}>
|
||||
<input type="checkbox" name="isActive" value="1" defaultChecked /> Active
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: '0.75rem' }}>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Create banner
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{banners.length === 0 ? (
|
||||
<p className="muted">No banners yet.</p>
|
||||
) : (
|
||||
<div className="grid">
|
||||
{banners.map((b) => (
|
||||
<div key={String(b.id)} className="card">
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'baseline',
|
||||
gap: '0.75rem',
|
||||
}}
|
||||
>
|
||||
<strong>#{String(b.id)}</strong>
|
||||
<span className="muted">
|
||||
by user {String(b.userId)} · {formatDate(b.createdAt)} ·{' '}
|
||||
{b.isActive ? 'active' : 'hidden'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{b.imagePath ? (
|
||||
<img
|
||||
src={b.imagePath}
|
||||
alt={b.title ?? 'Radio banner'}
|
||||
className="article-img"
|
||||
style={{ margin: '0.5rem 0' }}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<form action={updateRadioBanner}>
|
||||
<input type="hidden" name="id" value={String(b.id)} />
|
||||
<div className="grid cols-2">
|
||||
<div>
|
||||
<label
|
||||
htmlFor={`img_${b.id}`}
|
||||
style={{ display: 'block', fontWeight: 700 }}
|
||||
>
|
||||
Image path / URL
|
||||
</label>
|
||||
<input
|
||||
id={`img_${b.id}`}
|
||||
name="imagePath"
|
||||
defaultValue={b.imagePath}
|
||||
required
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
htmlFor={`title_${b.id}`}
|
||||
style={{ display: 'block', fontWeight: 700 }}
|
||||
>
|
||||
Title
|
||||
</label>
|
||||
<input
|
||||
id={`title_${b.id}`}
|
||||
name="title"
|
||||
defaultValue={b.title ?? ''}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ gridColumn: '1 / -1' }}>
|
||||
<label
|
||||
htmlFor={`desc_${b.id}`}
|
||||
style={{ display: 'block', fontWeight: 700 }}
|
||||
>
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
id={`desc_${b.id}`}
|
||||
name="description"
|
||||
rows={2}
|
||||
defaultValue={b.description ?? ''}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
htmlFor={`sort_${b.id}`}
|
||||
style={{ display: 'block', fontWeight: 700 }}
|
||||
>
|
||||
Sort order
|
||||
</label>
|
||||
<input
|
||||
id={`sort_${b.id}`}
|
||||
name="sortOrder"
|
||||
type="number"
|
||||
defaultValue={b.sortOrder}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'flex-end' }}>
|
||||
<label
|
||||
style={{ display: 'inline-flex', gap: '0.4rem', alignItems: 'center' }}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isActive"
|
||||
value="1"
|
||||
defaultChecked={b.isActive}
|
||||
/>{' '}
|
||||
Active
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: '0.6rem' }}>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form action={deleteRadioBanner} style={{ marginTop: '0.5rem' }}>
|
||||
<input type="hidden" name="id" value={String(b.id)} />
|
||||
<button type="submit" className="btn btn-danger">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import Link from 'next/link';
|
||||
import {
|
||||
createRadioRank,
|
||||
deleteRadioRank,
|
||||
updateRadioRank,
|
||||
} from '@/actions/admin-radio-extra';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
type Rank = {
|
||||
id: bigint;
|
||||
name: string;
|
||||
description: string | null;
|
||||
badgeCode: string | null;
|
||||
isActive: boolean;
|
||||
};
|
||||
|
||||
export default async function AdminRadioRanksPage() {
|
||||
let ranks: Rank[] = [];
|
||||
let dbError = false;
|
||||
|
||||
try {
|
||||
ranks = await prisma.radioRanks.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
description: true,
|
||||
badgeCode: true,
|
||||
isActive: true,
|
||||
},
|
||||
orderBy: { id: 'asc' },
|
||||
});
|
||||
} catch {
|
||||
dbError = true;
|
||||
ranks = [];
|
||||
}
|
||||
|
||||
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/banners">Banners</Link> ·{' '}
|
||||
<Link href="/admin/radio/ranks">Ranks</Link>
|
||||
</nav>
|
||||
|
||||
<h1>Radio Ranks</h1>
|
||||
<p className="muted">DJ / staff ranks assignable on radio applications.</p>
|
||||
|
||||
{dbError ? (
|
||||
<div className="card" style={{ marginBottom: '1.5rem' }}>
|
||||
<p className="muted" style={{ margin: 0 }}>
|
||||
Could not load ranks (database unavailable).
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<form action={createRadioRank} className="card" style={{ marginBottom: '1.5rem' }}>
|
||||
<h3 style={{ marginTop: 0 }}>Add rank</h3>
|
||||
<div className="grid cols-3">
|
||||
<div>
|
||||
<label htmlFor="new_name" style={{ display: 'block', fontWeight: 700 }}>
|
||||
Name
|
||||
</label>
|
||||
<input id="new_name" name="name" required style={{ width: '100%' }} />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="new_badge" style={{ display: 'block', fontWeight: 700 }}>
|
||||
Badge code
|
||||
</label>
|
||||
<input id="new_badge" name="badgeCode" style={{ width: '100%' }} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'flex-end' }}>
|
||||
<label style={{ display: 'inline-flex', gap: '0.4rem', alignItems: 'center' }}>
|
||||
<input type="checkbox" name="isActive" value="1" defaultChecked /> Active
|
||||
</label>
|
||||
</div>
|
||||
<div style={{ gridColumn: '1 / -1' }}>
|
||||
<label htmlFor="new_desc" style={{ display: 'block', fontWeight: 700 }}>
|
||||
Description
|
||||
</label>
|
||||
<input id="new_desc" name="description" style={{ width: '100%' }} />
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: '0.75rem' }}>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Create rank
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{ranks.length === 0 ? (
|
||||
<p className="muted">No ranks yet.</p>
|
||||
) : (
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Badge</th>
|
||||
<th>Description</th>
|
||||
<th>Active</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{ranks.map((r) => (
|
||||
<tr key={String(r.id)}>
|
||||
<td>{String(r.id)}</td>
|
||||
<td colSpan={5}>
|
||||
<form
|
||||
action={updateRadioRank}
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: '0.5rem',
|
||||
alignItems: 'center',
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="id" value={String(r.id)} />
|
||||
<input
|
||||
name="name"
|
||||
defaultValue={r.name}
|
||||
required
|
||||
placeholder="Name"
|
||||
style={{ minWidth: 140 }}
|
||||
/>
|
||||
<input
|
||||
name="badgeCode"
|
||||
defaultValue={r.badgeCode ?? ''}
|
||||
placeholder="Badge"
|
||||
style={{ minWidth: 100 }}
|
||||
/>
|
||||
<input
|
||||
name="description"
|
||||
defaultValue={r.description ?? ''}
|
||||
placeholder="Description"
|
||||
style={{ flex: 1, minWidth: 160 }}
|
||||
/>
|
||||
<label
|
||||
style={{ display: 'inline-flex', gap: '0.3rem', alignItems: 'center' }}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isActive"
|
||||
value="1"
|
||||
defaultChecked={r.isActive}
|
||||
/>{' '}
|
||||
Active
|
||||
</label>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{ranks.map((r) => (
|
||||
<tr key={`del_${String(r.id)}`}>
|
||||
<td colSpan={6} style={{ borderTop: 'none', paddingTop: 0 }}>
|
||||
<form action={deleteRadioRank} style={{ display: 'inline' }}>
|
||||
<input type="hidden" name="id" value={String(r.id)} />
|
||||
<button type="submit" className="btn btn-danger">
|
||||
Delete rank #{String(r.id)}
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
import Link from 'next/link';
|
||||
import { saveRadioSetting, saveRadioSettings } from '@/actions/admin-radio-extra';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
// Curated radio_* keys (faithful to AtomCMS RadioSettingsSeeder), grouped for
|
||||
// the editor. Any extra radio_* rows found in the DB are appended under "Other".
|
||||
type Field = { key: string; comment: string };
|
||||
type Group = { title: string; fields: Field[] };
|
||||
|
||||
const GROUPS: Group[] = [
|
||||
{
|
||||
title: 'AzureCast & Stream',
|
||||
fields: [
|
||||
{ key: 'radio_enabled', comment: 'Radio enabled (0=no, 1=yes)' },
|
||||
{ key: 'radio_stream_url', comment: 'Main stream URL' },
|
||||
{ key: 'radio_stream_backup_url', comment: 'Backup stream URL' },
|
||||
{ key: 'radio_azurecast_base_url', comment: 'AzureCast base URL' },
|
||||
{ key: 'radio_azurecast_station_id', comment: 'AzureCast station ID' },
|
||||
{ key: 'radio_azurecast_api_key', comment: 'AzureCast API key' },
|
||||
{ key: 'radio_azurecast_port', comment: 'AzureCast stream port' },
|
||||
{ key: 'radio_azurecast_protocol', comment: 'AzureCast protocol (http/https)' },
|
||||
{ key: 'radio_azurecast_use_proxy', comment: 'Use AzureCast proxy (0=no, 1=yes)' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'External sources',
|
||||
fields: [
|
||||
{ key: 'radio_sambroadcaster_api_url', comment: 'Sambroadcaster API URL' },
|
||||
{ key: 'radio_sambroadcaster_password', comment: 'Sambroadcaster password' },
|
||||
{ key: 'radio_virtual_dj_url', comment: 'Virtual DJ URL' },
|
||||
{ key: 'radio_virtual_dj_password', comment: 'Virtual DJ password' },
|
||||
{ key: 'radio_djs_api_url', comment: 'DJs API URL' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Player',
|
||||
fields: [
|
||||
{ key: 'radio_style', comment: 'Player style (dark/light/blue/purple/pink/gold)' },
|
||||
{ key: 'radio_player_type', comment: 'Player type (default/minimal/embedded)' },
|
||||
{ key: 'radio_auto_play', comment: 'Auto-play on page load (0=no, 1=yes)' },
|
||||
{ key: 'radio_auto_play_delay', comment: 'Auto-play delay in seconds' },
|
||||
{ key: 'radio_mute_on_start', comment: 'Muted on start (0=no, 1=yes)' },
|
||||
{ key: 'radio_volume', comment: 'Default volume (0-100)' },
|
||||
{ key: 'radio_language', comment: 'Default language (nl/en/de/fr/es/pt/it/br)' },
|
||||
{ key: 'radio_multi_language_enabled', comment: 'Multi-language support (0=no, 1=yes)' },
|
||||
{ key: 'radio_player_color_primary', comment: 'Player primary color' },
|
||||
{ key: 'radio_player_color_secondary', comment: 'Player secondary color' },
|
||||
{ key: 'radio_player_color_text', comment: 'Player text color' },
|
||||
{ key: 'radio_player_color_accent', comment: 'Player accent color' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Now playing & history',
|
||||
fields: [
|
||||
{ key: 'radio_now_playing_enabled', comment: 'Show now playing info (0=no, 1=yes)' },
|
||||
{ key: 'radio_now_playing_api_url', comment: 'Now playing API URL' },
|
||||
{ key: 'radio_now_playing_cache_duration', comment: 'Now playing cache duration in seconds' },
|
||||
{ key: 'radio_show_song_history', comment: 'Show song history (0=no, 1=yes)' },
|
||||
{ key: 'radio_song_history_count', comment: 'Number of songs in history' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Listeners',
|
||||
fields: [
|
||||
{ key: 'radio_listeners_enabled', comment: 'Show listeners count (0=no, 1=yes)' },
|
||||
{ key: 'radio_listeners_api_url', comment: 'Listeners API URL' },
|
||||
{ key: 'radio_listeners_update_interval', comment: 'Listeners update interval in seconds' },
|
||||
{ key: 'radio_show_listener_peak', comment: 'Show listener peak (0=no, 1=yes)' },
|
||||
{ key: 'radio_peak_reset_time', comment: 'Peak reset time (HH:MM)' },
|
||||
{ key: 'radio_store_listener_stats', comment: 'Store listener statistics (0=no, 1=yes)' },
|
||||
{ key: 'radio_stats_retention_days', comment: 'Statistics retention in days' },
|
||||
{ key: 'radio_show_listener_graph', comment: 'Show listener graph (0=no, 1=yes)' },
|
||||
{ key: 'radio_listener_graph_period', comment: 'Listener graph period (1h/6h/12h/24h/7d)' },
|
||||
{ key: 'radio_show_average_listeners', comment: 'Show average listeners (0=no, 1=yes)' },
|
||||
{ key: 'radio_show_unique_listeners', comment: 'Show unique listeners (0=no, 1=yes)' },
|
||||
{ key: 'radio_listener_alerts_enabled', comment: 'Enable listener alerts (0=no, 1=yes)' },
|
||||
{ key: 'radio_min_listeners_threshold', comment: 'Minimum listeners threshold' },
|
||||
{ key: 'radio_listener_alert_threshold_high', comment: 'High listener alert threshold' },
|
||||
{ key: 'radio_listener_alert_threshold_low', comment: 'Low listener alert threshold' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'DJ',
|
||||
fields: [
|
||||
{ key: 'radio_show_current_dj', comment: 'Show current DJ (0=no, 1=yes)' },
|
||||
{ key: 'radio_current_dj_id', comment: 'Manual DJ user ID' },
|
||||
{ key: 'radio_dj_avatar_size', comment: 'DJ avatar size in pixels' },
|
||||
{ key: 'radio_show_dj_schedule', comment: 'Show DJ schedule (0=no, 1=yes)' },
|
||||
{ key: 'radio_auto_dj_detection', comment: 'Enable auto DJ detection (0=no, 1=yes)' },
|
||||
{ key: 'radio_dj_detection_interval', comment: 'DJ detection interval in seconds' },
|
||||
{ key: 'auto_dj_detected_action', comment: 'Action on DJ detection (set_dj/notify/both)' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Shouts & chat',
|
||||
fields: [
|
||||
{ key: 'radio_shouts_enabled', comment: 'Enable shouts (0=no, 1=yes)' },
|
||||
{ key: 'radio_shouts_max_length', comment: 'Maximum shout length in characters' },
|
||||
{ key: 'radio_shouts_cooldown', comment: 'Shout cooldown in seconds' },
|
||||
{ key: 'radio_shouts_require_moderation', comment: 'Require shout moderation (0=no, 1=yes)' },
|
||||
{ key: 'radio_chat_enabled', comment: 'Enable live chat (0=no, 1=yes)' },
|
||||
{ key: 'radio_chat_position', comment: 'Chat position (left/right/bottom)' },
|
||||
{ key: 'radio_chat_width', comment: 'Chat width in pixels' },
|
||||
{ key: 'radio_chat_height', comment: 'Chat height in pixels' },
|
||||
{ key: 'radio_chat_messages_count', comment: 'Number of chat messages to show' },
|
||||
{ key: 'radio_chat_show_timestamps', comment: 'Show chat timestamps (0=no, 1=yes)' },
|
||||
{ key: 'radio_chat_allow_links', comment: 'Allow links in chat (0=no, 1=yes)' },
|
||||
{ key: 'radio_chat_allow_emojis', comment: 'Allow emojis in chat (0=no, 1=yes)' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Requests & widget',
|
||||
fields: [
|
||||
{ key: 'radio_request_form_enabled', comment: 'Enable song requests (0=no, 1=yes)' },
|
||||
{ key: 'radio_request_max_per_user', comment: 'Maximum requests per user' },
|
||||
{ key: 'radio_request_cooldown', comment: 'Request cooldown in seconds' },
|
||||
{ key: 'radio_voting_enabled', comment: 'Enable request voting (0=no, 1=yes)' },
|
||||
{ key: 'radio_voting_show_song_requests', comment: 'Show requests with votes (0=no, 1=yes)' },
|
||||
{ key: 'radio_widget_enabled', comment: 'Enable radio widget (0=no, 1=yes)' },
|
||||
{ key: 'radio_widget_show_globally', comment: 'Show widget globally (0=no, 1=yes)' },
|
||||
{ key: 'radio_widget_position', comment: 'Widget position' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Offline & branding',
|
||||
fields: [
|
||||
{ key: 'radio_show_offline_message', comment: 'Show offline message (0=no, 1=yes)' },
|
||||
{ key: 'radio_offline_message', comment: 'Offline message text' },
|
||||
{ key: 'radio_offline_image', comment: 'Offline page image URL' },
|
||||
{ key: 'radio_background_image', comment: 'Background image URL' },
|
||||
{ key: 'radio_logo_url', comment: 'Radio logo URL' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Applications',
|
||||
fields: [
|
||||
{ key: 'radio_applications_enabled', comment: 'Enable DJ applications (0=no, 1=yes)' },
|
||||
{ key: 'radio_applications_max_per_day', comment: 'Maximum applications per day' },
|
||||
{ key: 'radio_applications_require_approval', comment: 'Require application approval (0=no, 1=yes)' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Stats display',
|
||||
fields: [
|
||||
{ key: 'radio_stats_show_daily', comment: 'Show daily statistics (0=no, 1=yes)' },
|
||||
{ key: 'radio_stats_show_weekly', comment: 'Show weekly statistics (0=no, 1=yes)' },
|
||||
{ key: 'radio_stats_show_monthly', comment: 'Show monthly statistics (0=no, 1=yes)' },
|
||||
{ key: 'radio_stats_show_top_djs', comment: 'Show top DJs (0=no, 1=yes)' },
|
||||
{ key: 'radio_stats_show_top_songs', comment: 'Show top songs (0=no, 1=yes)' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Social & contact',
|
||||
fields: [
|
||||
{ key: 'radio_social_facebook', comment: 'Facebook URL' },
|
||||
{ key: 'radio_social_twitter', comment: 'Twitter URL' },
|
||||
{ key: 'radio_social_instagram', comment: 'Instagram URL' },
|
||||
{ key: 'radio_social_discord', comment: 'Discord URL' },
|
||||
{ key: 'radio_social_youtube', comment: 'YouTube URL' },
|
||||
{ key: 'radio_social_twitch', comment: 'Twitch URL' },
|
||||
{ key: 'radio_contact_email', comment: 'Contact email' },
|
||||
{ key: 'radio_contact_phone', comment: 'Contact phone' },
|
||||
{ key: 'radio_about_text', comment: 'About radio text' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Discord webhook & custom code',
|
||||
fields: [
|
||||
{ key: 'radio_discord_webhook_url', comment: 'Discord webhook URL' },
|
||||
{ key: 'radio_discord_enabled', comment: 'Enable Discord notifications (0=no, 1=yes)' },
|
||||
{ key: 'radio_discord_dj_live', comment: 'Discord DJ live notification (0=no, 1=yes)' },
|
||||
{ key: 'radio_discord_song_changes', comment: 'Discord song change notification (0=no, 1=yes)' },
|
||||
{ key: 'radio_discord_custom_message', comment: 'Custom Discord message template' },
|
||||
{ key: 'radio_custom_css', comment: 'Custom CSS code' },
|
||||
{ key: 'radio_custom_js', comment: 'Custom JavaScript code' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const CURATED_KEYS = new Set(GROUPS.flatMap((g) => g.fields.map((f) => f.key)));
|
||||
|
||||
export default async function AdminRadioSettingsPage() {
|
||||
let values: Map<string, string> = new Map();
|
||||
let dbError = false;
|
||||
let extra: Field[] = [];
|
||||
|
||||
try {
|
||||
const rows = await prisma.websiteSetting.findMany({
|
||||
select: { key: true, value: true, comment: true },
|
||||
});
|
||||
values = new Map(rows.map((r) => [r.key, r.value]));
|
||||
extra = rows
|
||||
.filter(
|
||||
(r) =>
|
||||
(r.key.startsWith('radio_') || r.key.startsWith('auto_dj_')) &&
|
||||
!CURATED_KEYS.has(r.key),
|
||||
)
|
||||
.map((r) => ({ key: r.key, comment: r.comment ?? '' }));
|
||||
} catch {
|
||||
dbError = true;
|
||||
}
|
||||
|
||||
const groups: Group[] = extra.length
|
||||
? [...GROUPS, { title: 'Other radio settings', fields: extra }]
|
||||
: GROUPS;
|
||||
|
||||
const allKeys = [...CURATED_KEYS, ...extra.map((e) => e.key)].join(',');
|
||||
|
||||
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/banners">Banners</Link> ·{' '}
|
||||
<Link href="/admin/radio/ranks">Ranks</Link>
|
||||
</nav>
|
||||
|
||||
<h1>Radio Settings</h1>
|
||||
<p className="muted">
|
||||
Edits write to <code>website_settings</code> (radio_* keys) and bust the
|
||||
runtime settings cache. Booleans use <code>0</code> / <code>1</code>.
|
||||
</p>
|
||||
|
||||
{dbError ? (
|
||||
<div className="card" style={{ marginBottom: '1.5rem' }}>
|
||||
<p className="muted" style={{ margin: 0 }}>
|
||||
Could not load settings (database unavailable). Defaults will be
|
||||
created on save.
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<form action={saveRadioSettings}>
|
||||
<input type="hidden" name="__keys" value={allKeys} />
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'flex-end',
|
||||
marginBottom: '1rem',
|
||||
}}
|
||||
>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save all
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{groups.map((group) => (
|
||||
<section key={group.title} className="card" style={{ marginBottom: '1.25rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>{group.title}</h2>
|
||||
<div className="grid cols-2">
|
||||
{group.fields.map((field) => (
|
||||
<div key={field.key}>
|
||||
<label
|
||||
htmlFor={`f_${field.key}`}
|
||||
style={{ display: 'block', fontWeight: 700, fontSize: '0.85rem' }}
|
||||
>
|
||||
{field.key}
|
||||
</label>
|
||||
<input
|
||||
id={`f_${field.key}`}
|
||||
name={field.key}
|
||||
defaultValue={values.get(field.key) ?? ''}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
{field.comment ? (
|
||||
<p className="muted" style={{ margin: '0.2rem 0 0' }}>
|
||||
{field.comment}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
))}
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save all
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<section className="card" style={{ marginTop: '1.5rem' }}>
|
||||
<h3 style={{ marginTop: 0 }}>Add / overwrite a single key</h3>
|
||||
<form
|
||||
action={saveRadioSetting}
|
||||
style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}
|
||||
>
|
||||
<input name="key" placeholder="radio_custom_key" required />
|
||||
<input name="value" placeholder="value" style={{ flex: 1, minWidth: 160 }} />
|
||||
<input name="comment" placeholder="comment (optional)" />
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Save
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user