Revert "Add missing admin action files and navigation links"
This reverts commit 41be6835bf.
This commit is contained in:
1 parent
4a1e1115b3
commit
4d515bc400
338 files changed
+5949
-28144
No files matched your search
@@ -1,15 +1,15 @@
|
||||
"use server";
|
||||
'use server';
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { requireStaff } from "@/lib/admin/guard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { requireStaff } from '@/lib/admin/guard';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { siteSettings } from '@/lib/services/site-settings';
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Parse a FormData field into a positive BigInt id, or null when invalid. */
|
||||
function parseId(raw: FormDataEntryValue | null): bigint | null {
|
||||
if (typeof raw !== "string" || raw.trim() === "") return null;
|
||||
if (typeof raw !== 'string' || raw.trim() === '') return null;
|
||||
try {
|
||||
const id = BigInt(raw.trim());
|
||||
return id > 0n ? id : null;
|
||||
@@ -19,13 +19,13 @@ function parseId(raw: FormDataEntryValue | null): bigint | null {
|
||||
}
|
||||
|
||||
function str(raw: FormDataEntryValue | null): string {
|
||||
return typeof raw === "string" ? raw : "";
|
||||
return typeof raw === 'string' ? raw : '';
|
||||
}
|
||||
|
||||
/** Checkbox/select truthiness: '1', 'true', 'on' → true. */
|
||||
function bool(raw: FormDataEntryValue | null): boolean {
|
||||
const v = str(raw).trim().toLowerCase();
|
||||
return v === "1" || v === "true" || v === "on";
|
||||
return v === '1' || v === 'true' || v === 'on';
|
||||
}
|
||||
|
||||
// ── Radio settings (website_settings radio_* keys) ─────────────────────────
|
||||
@@ -37,9 +37,9 @@ function bool(raw: FormDataEntryValue | null): boolean {
|
||||
*/
|
||||
export async function saveRadioSetting(formData: FormData): Promise<void> {
|
||||
await requireStaff();
|
||||
const key = str(formData.get("key")).trim().slice(0, 255);
|
||||
const value = str(formData.get("value"));
|
||||
const comment = str(formData.get("comment")).trim().slice(0, 255);
|
||||
const key = str(formData.get('key')).trim().slice(0, 255);
|
||||
const value = str(formData.get('value'));
|
||||
const comment = str(formData.get('comment')).trim().slice(0, 255);
|
||||
if (!key) return;
|
||||
|
||||
try {
|
||||
@@ -52,7 +52,7 @@ export async function saveRadioSetting(formData: FormData): Promise<void> {
|
||||
} catch {
|
||||
// DB unavailable — fail soft so the action does not throw.
|
||||
}
|
||||
revalidatePath("/admin/radio/settings");
|
||||
revalidatePath('/admin/radio/settings');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,11 +62,11 @@ export async function saveRadioSetting(formData: FormData): Promise<void> {
|
||||
*/
|
||||
export async function saveRadioSettings(formData: FormData): Promise<void> {
|
||||
await requireStaff();
|
||||
const keysRaw = str(formData.get("__keys"));
|
||||
const keysRaw = str(formData.get('__keys'));
|
||||
const keys = keysRaw
|
||||
.split(",")
|
||||
.split(',')
|
||||
.map((k) => k.trim())
|
||||
.filter((k) => k.startsWith("radio_") || k.startsWith("auto_dj_"));
|
||||
.filter((k) => k.startsWith('radio_') || k.startsWith('auto_dj_'));
|
||||
if (keys.length === 0) return;
|
||||
|
||||
try {
|
||||
@@ -84,21 +84,21 @@ export async function saveRadioSettings(formData: FormData): Promise<void> {
|
||||
} catch {
|
||||
// Fail soft.
|
||||
}
|
||||
revalidatePath("/admin/radio/settings");
|
||||
revalidatePath('/admin/radio/settings');
|
||||
}
|
||||
|
||||
// ── Radio banners CRUD (radio_banners) ─────────────────────────────────────
|
||||
|
||||
export async function createRadioBanner(formData: FormData): Promise<void> {
|
||||
const staff = await requireStaff();
|
||||
const imagePath = str(formData.get("imagePath")).trim().slice(0, 255);
|
||||
const imagePath = str(formData.get('imagePath')).trim().slice(0, 255);
|
||||
if (!imagePath) return;
|
||||
|
||||
const title = str(formData.get("title")).trim().slice(0, 255);
|
||||
const description = str(formData.get("description")).trim();
|
||||
const sortOrderNum = Number(str(formData.get("sortOrder")));
|
||||
const title = str(formData.get('title')).trim().slice(0, 255);
|
||||
const description = str(formData.get('description')).trim();
|
||||
const sortOrderNum = Number(str(formData.get('sortOrder')));
|
||||
const sortOrder = Number.isFinite(sortOrderNum) ? Math.trunc(sortOrderNum) : 0;
|
||||
const isActive = bool(formData.get("isActive"));
|
||||
const isActive = bool(formData.get('isActive'));
|
||||
const now = new Date();
|
||||
|
||||
try {
|
||||
@@ -117,20 +117,20 @@ export async function createRadioBanner(formData: FormData): Promise<void> {
|
||||
} catch {
|
||||
// Fail soft.
|
||||
}
|
||||
revalidatePath("/admin/radio/banners");
|
||||
revalidatePath('/admin/radio/banners');
|
||||
}
|
||||
|
||||
export async function updateRadioBanner(formData: FormData): Promise<void> {
|
||||
await requireStaff();
|
||||
const id = parseId(formData.get("id"));
|
||||
const id = parseId(formData.get('id'));
|
||||
if (id === null) return;
|
||||
|
||||
const imagePath = str(formData.get("imagePath")).trim().slice(0, 255);
|
||||
const title = str(formData.get("title")).trim().slice(0, 255);
|
||||
const description = str(formData.get("description")).trim();
|
||||
const sortOrderNum = Number(str(formData.get("sortOrder")));
|
||||
const imagePath = str(formData.get('imagePath')).trim().slice(0, 255);
|
||||
const title = str(formData.get('title')).trim().slice(0, 255);
|
||||
const description = str(formData.get('description')).trim();
|
||||
const sortOrderNum = Number(str(formData.get('sortOrder')));
|
||||
const sortOrder = Number.isFinite(sortOrderNum) ? Math.trunc(sortOrderNum) : 0;
|
||||
const isActive = bool(formData.get("isActive"));
|
||||
const isActive = bool(formData.get('isActive'));
|
||||
if (!imagePath) return;
|
||||
|
||||
try {
|
||||
@@ -148,31 +148,31 @@ export async function updateRadioBanner(formData: FormData): Promise<void> {
|
||||
} catch {
|
||||
// Row may be gone; ignore.
|
||||
}
|
||||
revalidatePath("/admin/radio/banners");
|
||||
revalidatePath('/admin/radio/banners');
|
||||
}
|
||||
|
||||
export async function deleteRadioBanner(formData: FormData): Promise<void> {
|
||||
await requireStaff();
|
||||
const id = parseId(formData.get("id"));
|
||||
const id = parseId(formData.get('id'));
|
||||
if (id === null) return;
|
||||
try {
|
||||
await prisma.radioBanners.delete({ where: { id } });
|
||||
} catch {
|
||||
// Already deleted; ignore.
|
||||
}
|
||||
revalidatePath("/admin/radio/banners");
|
||||
revalidatePath('/admin/radio/banners');
|
||||
}
|
||||
|
||||
// ── Radio ranks CRUD (radio_ranks) ─────────────────────────────────────────
|
||||
|
||||
export async function createRadioRank(formData: FormData): Promise<void> {
|
||||
await requireStaff();
|
||||
const name = str(formData.get("name")).trim().slice(0, 255);
|
||||
const name = str(formData.get('name')).trim().slice(0, 255);
|
||||
if (!name) return;
|
||||
|
||||
const description = str(formData.get("description")).trim().slice(0, 255);
|
||||
const badgeCode = str(formData.get("badgeCode")).trim().slice(0, 255);
|
||||
const isActive = bool(formData.get("isActive"));
|
||||
const description = str(formData.get('description')).trim().slice(0, 255);
|
||||
const badgeCode = str(formData.get('badgeCode')).trim().slice(0, 255);
|
||||
const isActive = bool(formData.get('isActive'));
|
||||
const now = new Date();
|
||||
|
||||
try {
|
||||
@@ -189,18 +189,18 @@ export async function createRadioRank(formData: FormData): Promise<void> {
|
||||
} catch {
|
||||
// Fail soft.
|
||||
}
|
||||
revalidatePath("/admin/radio/ranks");
|
||||
revalidatePath('/admin/radio/ranks');
|
||||
}
|
||||
|
||||
export async function updateRadioRank(formData: FormData): Promise<void> {
|
||||
await requireStaff();
|
||||
const id = parseId(formData.get("id"));
|
||||
const id = parseId(formData.get('id'));
|
||||
if (id === null) return;
|
||||
|
||||
const name = str(formData.get("name")).trim().slice(0, 255);
|
||||
const description = str(formData.get("description")).trim().slice(0, 255);
|
||||
const badgeCode = str(formData.get("badgeCode")).trim().slice(0, 255);
|
||||
const isActive = bool(formData.get("isActive"));
|
||||
const name = str(formData.get('name')).trim().slice(0, 255);
|
||||
const description = str(formData.get('description')).trim().slice(0, 255);
|
||||
const badgeCode = str(formData.get('badgeCode')).trim().slice(0, 255);
|
||||
const isActive = bool(formData.get('isActive'));
|
||||
if (!name) return;
|
||||
|
||||
try {
|
||||
@@ -217,17 +217,17 @@ export async function updateRadioRank(formData: FormData): Promise<void> {
|
||||
} catch {
|
||||
// Row may be gone; ignore.
|
||||
}
|
||||
revalidatePath("/admin/radio/ranks");
|
||||
revalidatePath('/admin/radio/ranks');
|
||||
}
|
||||
|
||||
export async function deleteRadioRank(formData: FormData): Promise<void> {
|
||||
await requireStaff();
|
||||
const id = parseId(formData.get("id"));
|
||||
const id = parseId(formData.get('id'));
|
||||
if (id === null) return;
|
||||
try {
|
||||
await prisma.radioRanks.delete({ where: { id } });
|
||||
} catch {
|
||||
// Already deleted; ignore.
|
||||
}
|
||||
revalidatePath("/admin/radio/ranks");
|
||||
revalidatePath('/admin/radio/ranks');
|
||||
}
|
||||
Reference in new issue
Block a user