import { db } from "@/lib/db" import { NextResponse } from "next/server"; import fetchUserWithImpersonation from "@/lib/fetch-user-impersonation"; import voices from "@/data/tts"; export async function GET(req: Request) { try { const user = await fetchUserWithImpersonation(req) if (!user) { return new NextResponse("Unauthorized", { status: 401 }); } const u = await db.user.findFirst({ where: { id: user.id } }); let list : { value: string; label: string; gender: string; language: string; }[] = [] const enabled = u?.ttsEnabledVoice ?? 0 for (let i = 0; i < voices.length; i++) { var v = voices[i] var n = Number.parseInt(v.value) - 1 if ((enabled & (1 << n)) > 0) { list.push(v) } } return NextResponse.json(list); } catch (error) { console.log("[TTS/FILTER/USER]", error); return new NextResponse("Internal Error", { status: 500 }); } } export async function POST(req: Request) { try { const user = await fetchUserWithImpersonation(req) if (!user) { return new NextResponse("Unauthorized", { status: 401 }); } let { voice } = await req.json(); console.log(voice) voice = voice & ((1 << voices.length) - 1) await db.user.update({ where: { id: user.id }, data: { ttsEnabledVoice: voice } }); return new NextResponse("", { status: 200 }); } catch (error) { console.log("[TTS/FILTER/USER]", error); return new NextResponse("Internal Error", { status: 500 }); } }