Added some error message handling and added basic info about functionality on ui
This commit is contained in:
@ -19,7 +19,7 @@ export async function GET(req: Request) {
|
||||
const voice = voices.find(v => v.value == new String(u?.ttsDefaultVoice))
|
||||
return NextResponse.json(voice);
|
||||
} catch (error) {
|
||||
console.log("[TTS/FILTER/USER]", error);
|
||||
console.log("[TTS/FILTER/DEFAULT]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
||||
}
|
||||
@ -32,11 +32,9 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
const { voice } = await req.json();
|
||||
console.log(voice)
|
||||
if (!voice || !voices.map(v => v.label.toLowerCase()).includes(voice.toLowerCase())) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
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: {
|
||||
@ -49,7 +47,7 @@ export async function POST(req: Request) {
|
||||
|
||||
return new NextResponse("", { status: 200 });
|
||||
} catch (error) {
|
||||
console.log("[TTS/FILTER/USER]", error);
|
||||
console.log("[TTS/FILTER/DEFAULT]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
||||
}
|
@ -30,6 +30,8 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
const { username, tag } = await req.json();
|
||||
if (!username || username.length < 4 || username.length > 25) return new NextResponse("Bad Request", { status: 400 });
|
||||
if (!tag || !["blacklisted", "priority"].includes(tag)) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
const filter = await db.ttsUsernameFilter.upsert({
|
||||
where: {
|
||||
@ -64,6 +66,7 @@ export async function DELETE(req: Request) {
|
||||
|
||||
const { searchParams } = new URL(req.url)
|
||||
const username = searchParams.get('username') as string
|
||||
if (!username || username.length < 4 || username.length > 25) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
const filter = await db.ttsUsernameFilter.delete({
|
||||
where: {
|
||||
|
@ -30,6 +30,8 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
const { search, replace } = await req.json();
|
||||
if (!search || search.length < 4 || search.length > 200) return new NextResponse("Bad Request", { status: 400 });
|
||||
if (!replace) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
const filter = await db.ttsWordFilter.create({
|
||||
data: {
|
||||
@ -54,6 +56,9 @@ export async function PUT(req: Request) {
|
||||
}
|
||||
|
||||
const { id, search, replace } = await req.json();
|
||||
if (!id || id.length < 1) return new NextResponse("Bad Request", { status: 400 });
|
||||
if (!search || search.length < 4 || search.length > 200) return new NextResponse("Bad Request", { status: 400 });
|
||||
if (!replace) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
const filter = await db.ttsWordFilter.update({
|
||||
where: {
|
||||
@ -83,8 +88,11 @@ export async function DELETE(req: Request) {
|
||||
const { searchParams } = new URL(req.url)
|
||||
const id = searchParams.get('id') as string
|
||||
const search = searchParams.get('search') as string
|
||||
if (!id && !search) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
if (search) {
|
||||
if (search.length < 4 || search.length > 200) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
const filter = await db.ttsWordFilter.delete({
|
||||
where: {
|
||||
userId_search: {
|
||||
@ -96,6 +104,8 @@ export async function DELETE(req: Request) {
|
||||
|
||||
return NextResponse.json(filter)
|
||||
} else if (id) {
|
||||
if (id.length < 1) return new NextResponse("Bad Request", { status: 400 });
|
||||
|
||||
const filter = await db.ttsWordFilter.delete({
|
||||
where: {
|
||||
id: id
|
||||
|
@ -10,21 +10,14 @@ export async function GET(req: Request) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const u = await db.user.findFirst({
|
||||
where: {
|
||||
id: user.id
|
||||
}
|
||||
});
|
||||
|
||||
let list : {
|
||||
value: string;
|
||||
label: string;
|
||||
gender: string;
|
||||
language: string;
|
||||
}[] = []
|
||||
const enabled = u?.ttsEnabledVoice ?? 0
|
||||
for (let i = 0; i < voices.length; i++) {
|
||||
var v = voices[i]
|
||||
const enabled = user.ttsEnabledVoice
|
||||
for (let v of voices) {
|
||||
var n = Number.parseInt(v.value) - 1
|
||||
if ((enabled & (1 << n)) > 0) {
|
||||
list.push(v)
|
||||
@ -46,7 +39,6 @@ export async function POST(req: Request) {
|
||||
}
|
||||
|
||||
let { voice } = await req.json();
|
||||
console.log(voice)
|
||||
voice = voice & ((1 << voices.length) - 1)
|
||||
|
||||
await db.user.update({
|
||||
|
Reference in New Issue
Block a user