37 lines
949 B
TypeScript
37 lines
949 B
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { auth } from "@/lib/auth";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
const SONG_MAX = 255;
|
|
const ARTIST_MAX = 255;
|
|
|
|
export async function submitRequest(formData: FormData): Promise<void> {
|
|
const session = await auth();
|
|
const userId = Number(session?.user?.id);
|
|
if (!Number.isInteger(userId) || userId <= 0) return;
|
|
|
|
const songTitle = String(formData.get("songTitle") ?? "").trim().slice(0, SONG_MAX);
|
|
const artist = String(formData.get("artist") ?? "").trim().slice(0, ARTIST_MAX);
|
|
if (!songTitle && !artist) return;
|
|
|
|
const now = new Date();
|
|
try {
|
|
await prisma.radioSongRequests.create({
|
|
data: {
|
|
userId: BigInt(userId),
|
|
songTitle: songTitle || null,
|
|
artist: artist || null,
|
|
submittedAt: now,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
},
|
|
});
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
revalidatePath("/radio/requests");
|
|
}
|