Added redemptions & redeemable actions. Fixed a few bugs.
This commit is contained in:
@@ -5,19 +5,16 @@ 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 });
|
||||
}
|
||||
|
||||
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);
|
||||
return NextResponse.json(user.ttsDefaultVoice);
|
||||
} catch (error) {
|
||||
console.log("[TTS/FILTER/DEFAULT]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
@@ -26,28 +23,32 @@ export async function GET(req: Request) {
|
||||
|
||||
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.label.toLowerCase()).includes(voice.toLowerCase())) return new NextResponse("Bad Request", { status: 400 });
|
||||
if (!voice || !voices.map(v => v.toLowerCase()).includes(voice.toLowerCase())) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
const v = voices.find(v => v.label.toLowerCase() == voice.toLowerCase())
|
||||
const v = voices.find(v => v.toLowerCase() == voice.toLowerCase())
|
||||
|
||||
await db.user.update({
|
||||
where: {
|
||||
id: user.id
|
||||
},
|
||||
data: {
|
||||
ttsDefaultVoice: Number.parseInt(v.value)
|
||||
ttsDefaultVoice: v
|
||||
}
|
||||
});
|
||||
|
||||
return new NextResponse("", { status: 200 });
|
||||
} catch (error) {
|
||||
console.log("[TTS/FILTER/DEFAULT]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
Reference in New Issue
Block a user