Setup a very basic ui
This commit is contained in:
38
ui/src/app/api/settings/route.ts
Normal file
38
ui/src/app/api/settings/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const settings = await prisma.settings.findMany();
|
||||
return NextResponse.json(settings.reduce((acc, curr) => ({ ...acc, [curr.key]: curr.value }), {}));
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Failed to fetch settings' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { HF_TOKEN, TRAINING_FOLDER } = body;
|
||||
|
||||
// Upsert both settings
|
||||
await Promise.all([
|
||||
prisma.settings.upsert({
|
||||
where: { key: 'HF_TOKEN' },
|
||||
update: { value: HF_TOKEN },
|
||||
create: { key: 'HF_TOKEN', value: HF_TOKEN },
|
||||
}),
|
||||
prisma.settings.upsert({
|
||||
where: { key: 'TRAINING_FOLDER' },
|
||||
update: { value: TRAINING_FOLDER },
|
||||
create: { key: 'TRAINING_FOLDER', value: TRAINING_FOLDER },
|
||||
}),
|
||||
]);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Failed to update settings' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user