import { db } from "@/lib/db" import { NextResponse } from "next/server"; import fetchUserUsingAPI from "@/lib/validate-api"; import voices from "@/data/tts"; export async function GET(req: Request) { try { const user = await fetchUserUsingAPI(req) if (!user) { return new NextResponse("Unauthorized", { status: 401 }); } const u = await db.user.findFirst({ where: { id: user.id } }); const voice = voices.find(v => v.value == new String(u?.ttsDefaultVoice)) return NextResponse.json(voice); } 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 fetchUserUsingAPI(req) if (!user) { return new NextResponse("Unauthorized", { status: 401 }); } const { voice } = await req.json(); console.log(voice) const v = voices.find(v => v.label.toLowerCase() == voice.toLowerCase()) if (v == null) return new NextResponse("Bad Request", { status: 400 }); await db.user.update({ where: { id: user.id }, data: { ttsDefaultVoice: Number.parseInt(v.value) } }); return new NextResponse("", { status: 200 }); } catch (error) { console.log("[TTS/FILTER/USER]", error); return new NextResponse("Internal Error", { status: 500 }); } }