Added basic validation for requests
This commit is contained in:
@ -7,7 +7,7 @@ export async function GET(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserWithImpersonation(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const selected = await db.ttsChatVoice.findMany({
|
||||
@ -22,8 +22,7 @@ export async function GET(req: Request) {
|
||||
const data = selected.map(s => ({ chatter_id: new Number(s.chatterId), voice: voiceNamesMapped[s.ttsVoiceId] }))
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
console.log("[TTS/SELECTED]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,11 +30,12 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserWithImpersonation(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
return NextResponse.json({ message: 'Unauthorized.', error: null, value: null }, { status: 401 });
|
||||
}
|
||||
|
||||
const { voice, chatterId }: { voice: string, chatterId: number } = await req.json();
|
||||
if (!voice || !voices.map(v => v.toLowerCase()).includes(voice.toLowerCase())) return new NextResponse("Bad Request", { status: 400 });
|
||||
if (!voice || !voices.map(v => v.toLowerCase()).includes(voice.toLowerCase()))
|
||||
return NextResponse.json({ message: 'Voice does not exist.', error: null, value: null }, { status: 400 })
|
||||
|
||||
const v = voices.find(v => v.toLowerCase() == voice.toLowerCase())
|
||||
const voiceData = await db.ttsVoice.findFirst({
|
||||
@ -44,7 +44,7 @@ export async function POST(req: Request) {
|
||||
}
|
||||
})
|
||||
if (!voiceData)
|
||||
return new NextResponse("Bad Request", { status: 400 });
|
||||
return NextResponse.json({ message: 'Voice does not exist.', error: null, value: null }, { status: 400 })
|
||||
|
||||
await db.ttsChatVoice.upsert({
|
||||
where: {
|
||||
@ -63,9 +63,8 @@ export async function POST(req: Request) {
|
||||
}
|
||||
});
|
||||
|
||||
return new NextResponse("", { status: 200 });
|
||||
return NextResponse.json({ message: null, error: null, value: null }, { status: 200 })
|
||||
} catch (error) {
|
||||
console.log("[TTS/SELECTED]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
return NextResponse.json({ message: 'Something went wrong', error: error, value: null }, { status: 500 })
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user