Files
tonemark/src/routes/api/jobs/[id]/+server.ts
Giancarmine Salucci f70cefc5e9
All checks were successful
Build & Push Docker Image / test (push) Successful in 11s
Build & Push Docker Image / build-and-push (push) Successful in 42s
fix(progress): separate model warmup state
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-12 00:52:33 +02:00

30 lines
1.0 KiB
TypeScript

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