diff --git a/ui/src/app/api/img/delete/route.ts b/ui/src/app/api/img/delete/route.ts new file mode 100644 index 00000000..178d602d --- /dev/null +++ b/ui/src/app/api/img/delete/route.ts @@ -0,0 +1,34 @@ +import { NextResponse } from 'next/server'; +import fs from 'fs'; +import { getDatasetsRoot } from '@/app/api/datasets/utils'; + +export async function POST(request: Request) { + try { + const body = await request.json(); + const { imgPath } = body; + let datasetsPath = await getDatasetsRoot(); + // make sure the dataset path is in the image path + if (!imgPath.startsWith(datasetsPath)) { + return NextResponse.json({ error: 'Invalid image path' }, { status: 400 }); + } + + // if img doesnt exist, ignore + if (!fs.existsSync(imgPath)) { + return NextResponse.json({ success: true }); + } + + // delete it and return success + fs.unlinkSync(imgPath); + + // check for caption + const captionPath = imgPath.replace(/\.[^/.]+$/, '') + '.txt'; + if (fs.existsSync(captionPath)) { + // delete caption file + fs.unlinkSync(captionPath); + } + + return NextResponse.json({ success: true }); + } catch (error) { + return NextResponse.json({ error: 'Failed to create dataset' }, { status: 500 }); + } +} diff --git a/ui/src/app/datasets/[datasetName]/page.tsx b/ui/src/app/datasets/[datasetName]/page.tsx index 2a1a9105..cb178279 100644 --- a/ui/src/app/datasets/[datasetName]/page.tsx +++ b/ui/src/app/datasets/[datasetName]/page.tsx @@ -69,7 +69,12 @@ export default function DatasetPage({ params }: { params: { datasetName: string
{imgList.length === 0 &&

No images found

} {imgList.map(img => ( - + refreshImageList(datasetName)} + /> ))}
)} diff --git a/ui/src/components/DatasetImageCard.tsx b/ui/src/components/DatasetImageCard.tsx index 7b63893b..b597ba08 100644 --- a/ui/src/components/DatasetImageCard.tsx +++ b/ui/src/components/DatasetImageCard.tsx @@ -1,13 +1,22 @@ import React, { useRef, useEffect, useState, ReactNode } from 'react'; +import { FaTrashAlt } from 'react-icons/fa'; +import { openConfirm } from './ConfirmModal'; interface DatasetImageCardProps { imageUrl: string; alt: string; children?: ReactNode; className?: string; + onDelete?: () => void; } -const DatasetImageCard: React.FC = ({ imageUrl, alt, children, className = '' }) => { +const DatasetImageCard: React.FC = ({ + imageUrl, + alt, + children, + className = '', + onDelete = () => {}, +}) => { const cardRef = useRef(null); const [isVisible, setIsVisible] = useState(false); const [loaded, setLoaded] = useState(false); @@ -65,7 +74,7 @@ const DatasetImageCard: React.FC = ({ imageUrl, alt, chil className="relative w-full" style={{ paddingBottom: '100%' }} // Make it square > -
+
{isVisible && ( = ({ imageUrl, alt, chil /> )} {children &&
{children}
} +
+ +