mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-02-28 08:13:58 +00:00
Added controls to the jobs table
This commit is contained in:
32
ui/src/app/api/jobs/[jobID]/delete/route.ts
Normal file
32
ui/src/app/api/jobs/[jobID]/delete/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { getTrainingFolder } from '@/server/settings';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: { jobID: string } }) {
|
||||
const { jobID } = await params;
|
||||
|
||||
const job = await prisma.job.findUnique({
|
||||
where: { id: jobID },
|
||||
});
|
||||
|
||||
if (!job) {
|
||||
return NextResponse.json({ error: 'Job not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
const trainingRoot = await getTrainingFolder();
|
||||
const trainingFolder = path.join(trainingRoot, job.name);
|
||||
|
||||
if (fs.existsSync(trainingFolder)) {
|
||||
fs.rmdirSync(trainingFolder, { recursive: true });
|
||||
}
|
||||
|
||||
await prisma.job.delete({
|
||||
where: { id: jobID },
|
||||
});
|
||||
|
||||
return NextResponse.json(job);
|
||||
}
|
||||
Reference in New Issue
Block a user