2024-01-04 02:14:11 -05:00
|
|
|
import { db } from "@/lib/db"
|
|
|
|
import { NextResponse } from "next/server";
|
2024-01-04 16:57:32 -05:00
|
|
|
import fetchUserWithImpersonation from "@/lib/fetch-user-impersonation";
|
2024-01-04 02:14:11 -05:00
|
|
|
import voices from "@/data/tts";
|
|
|
|
|
|
|
|
export async function GET(req: Request) {
|
|
|
|
try {
|
2024-01-04 16:57:32 -05:00
|
|
|
const user = await fetchUserWithImpersonation(req)
|
2024-01-04 02:14:11 -05:00
|
|
|
if (!user) {
|
|
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
|
|
}
|
|
|
|
|
|
|
|
let list : {
|
|
|
|
value: string;
|
|
|
|
label: string;
|
|
|
|
gender: string;
|
|
|
|
language: string;
|
|
|
|
}[] = []
|
2024-01-06 15:17:04 -05:00
|
|
|
const enabled = user.ttsEnabledVoice
|
|
|
|
for (let v of voices) {
|
2024-01-04 02:14:11 -05:00
|
|
|
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 {
|
2024-01-04 16:57:32 -05:00
|
|
|
const user = await fetchUserWithImpersonation(req)
|
2024-01-04 02:14:11 -05:00
|
|
|
if (!user) {
|
|
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
|
|
}
|
|
|
|
|
|
|
|
let { voice } = await req.json();
|
|
|
|
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 });
|
|
|
|
}
|
|
|
|
}
|