import { json, error } from '@sveltejs/kit'; import { getJob, setJobStatus, deleteJob } from '$lib/server/db.js'; import { cancelJob } from '$lib/server/whisper.js'; import { rm } from 'fs/promises'; export async function GET({ params }) { const job = getJob(params.id); if (!job) throw error(404, 'Job not found'); return json(job); } const ACTIVE = new Set(['pending', 'downloading', 'preparing', 'warming_model', 'transcribing', 'processing']); export async function DELETE({ params }) { const job = getJob(params.id); if (!job) throw error(404, 'Job not found'); if (ACTIVE.has(job.status)) { // Cancel active job (keeps DB record) setJobStatus(params.id, 'cancelled', 0); // Best-effort: tell whisper to drop the queued job so it stops using GPU if (job.whisperJobId) cancelJob(job.whisperJobId).catch(() => {}); } else { // Hard-delete terminal job + clean up output files deleteJob(params.id); if (job.outputDir) rm(job.outputDir, { recursive: true, force: true }).catch(() => {}); } return new Response(null, { status: 204 }); }