Setup a very basic ui

This commit is contained in:
Jaret Burkett
2025-02-18 10:57:14 -07:00
parent b32d7e552b
commit b13fcc1039
27 changed files with 4708 additions and 0 deletions

View 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 });
}
}

View File

@@ -0,0 +1,55 @@
import { NextResponse } from 'next/server';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const id = searchParams.get('id');
try {
if (id) {
const training = await prisma.training.findUnique({
where: { id },
});
return NextResponse.json(training);
}
const trainings = await prisma.training.findMany({
orderBy: { created_at: 'desc' },
});
return NextResponse.json(trainings);
} catch (error) {
return NextResponse.json({ error: 'Failed to fetch training data' }, { status: 500 });
}
}
export async function POST(request: Request) {
try {
const body = await request.json();
const { id, name, run_data } = body;
if (id) {
// Update existing training
const training = await prisma.training.update({
where: { id },
data: {
name,
run_data: JSON.stringify(run_data),
},
});
return NextResponse.json(training);
} else {
// Create new training
const training = await prisma.training.create({
data: {
name,
run_data: JSON.stringify(run_data),
},
});
return NextResponse.json(training);
}
} catch (error) {
return NextResponse.json({ error: 'Failed to save training data' }, { status: 500 });
}
}