feat: add standalone admin video call test

This commit is contained in:
2026-09-16 21:41:43 +02:00
parent 906ea764ac
commit 8f5a074716
4 changed files with 134 additions and 20 deletions
@@ -0,0 +1,33 @@
import { randomUUID } from "node:crypto";
import { NextResponse } from "next/server";
import { getPayload } from "payload";
import config from "@payload-config";
import { createMeetingToken } from "@/lib/meeting/token";
export const dynamic = "force-dynamic";
/** Creates a short-lived, database-free test room for an authenticated admin. */
export async function POST(request: Request) {
try {
const payload = await getPayload({ config });
const { user } = await payload.auth({ headers: request.headers });
if (!user || user.collection !== "users" || user.role !== "admin") {
return NextResponse.json({ error: "Nicht autorisiert." }, { status: 401 });
}
const eventSlug = `test-${randomUUID()}`;
const { token } = createMeetingToken({
eventSlug,
name: typeof user.name === "string" && user.name.trim() ? user.name.trim() : "Host",
role: "host",
ttlMs: 60 * 60 * 1000,
});
const baseUrl = process.env.NEXT_PUBLIC_SERVER_URL || new URL(request.url).origin;
const testUrl = `${baseUrl.replace(/\/$/, "")}/termine/${encodeURIComponent(eventSlug)}/call#token=${encodeURIComponent(token)}`;
return NextResponse.json({ testUrl });
} catch (error) {
console.error("admin test meeting start failed", error);
return NextResponse.json({ error: "Der Test-Call konnte nicht gestartet werden." }, { status: 500 });
}
}
@@ -23,9 +23,12 @@ export async function POST(request: Request, { params }: Args) {
}
try {
const payload = await getPayload({ config });
const { docs } = await payload.find({ collection: "events", where: { slug: { equals: slug } }, limit: 1 });
if (!docs[0]?.isOnline) return NextResponse.json({ error: "Dieser Online-Termin wurde nicht gefunden." }, { status: 404 });
const isAdminTestRoom = meetingToken.role === "host" && slug.startsWith("test-");
if (!isAdminTestRoom) {
const payload = await getPayload({ config });
const { docs } = await payload.find({ collection: "events", where: { slug: { equals: slug } }, limit: 1 });
if (!docs[0]?.isOnline) return NextResponse.json({ error: "Dieser Online-Termin wurde nicht gefunden." }, { status: 404 });
}
const participantToken = await createLiveKitToken({
eventSlug: slug,