54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
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 {
|
|
if (!voices) {
|
|
return new NextResponse("Voices not available.", { status: 500 });
|
|
}
|
|
|
|
const user = await fetchUserWithImpersonation(req)
|
|
if (!user) {
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
}
|
|
|
|
return NextResponse.json(user.ttsDefaultVoice);
|
|
} catch (error) {
|
|
console.log("[TTS/FILTER/DEFAULT]", error);
|
|
return new NextResponse("Internal Error", { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function POST(req: Request) {
|
|
try {
|
|
if (!voices) {
|
|
return new NextResponse("Voices not available.", { status: 500 });
|
|
}
|
|
|
|
const user = await fetchUserWithImpersonation(req)
|
|
if (!user) {
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
}
|
|
|
|
const { voice } = await req.json();
|
|
if (!voice || !voices.map(v => v.toLowerCase()).includes(voice.toLowerCase())) return new NextResponse("Bad Request", { status: 400 });
|
|
|
|
const v = voices.find(v => v.toLowerCase() == voice.toLowerCase())
|
|
|
|
await db.user.update({
|
|
where: {
|
|
id: user.id
|
|
},
|
|
data: {
|
|
ttsDefaultVoice: v
|
|
}
|
|
});
|
|
|
|
return new NextResponse("", { status: 200 });
|
|
} catch (error) {
|
|
console.log("[TTS/FILTER/DEFAULT]", error);
|
|
}
|
|
return new NextResponse("Internal Error", { status: 500 });
|
|
} |