mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-04-27 01:39:20 +00:00
Add ability to delete samples from the ui
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import fs from 'fs';
|
||||
import { getDatasetsRoot } from '@/server/settings';
|
||||
import { getDatasetsRoot, getTrainingFolder } from '@/server/settings';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { imgPath } = body;
|
||||
let datasetsPath = await getDatasetsRoot();
|
||||
const trainingPath = await getTrainingFolder();
|
||||
|
||||
// make sure the dataset path is in the image path
|
||||
if (!imgPath.startsWith(datasetsPath)) {
|
||||
if (!imgPath.startsWith(datasetsPath) && !imgPath.startsWith(trainingPath)) {
|
||||
return NextResponse.json({ error: 'Invalid image path' }, { status: 400 });
|
||||
}
|
||||
|
||||
// make sure it is an image
|
||||
if (!/\.(jpg|jpeg|png|bmp|gif|tiff|webp)$/i.test(imgPath.toLowerCase())) {
|
||||
return NextResponse.json({ error: 'Not an image' }, { status: 400 });
|
||||
}
|
||||
|
||||
// if img doesnt exist, ignore
|
||||
if (!fs.existsSync(imgPath)) {
|
||||
return NextResponse.json({ success: true });
|
||||
|
||||
Reference in New Issue
Block a user