D2: Widen retry to upload-source jobs
- Remove http-only guard in retry endpoint (src/routes/api/jobs/[id]/retry/+server.ts)
- Extend pipeline.ts retryJob() to handle upload-source jobs:
read file from persistent storage, pass buffer to runJob
- Change saveUploadedFile() to save to DATA_DIR/uploads/{jobId}/
(survives cleanupJobTmp, available for retry on failure)
- Add getUploadPath(), cleanupUploadDir() to downloader.ts
- Remove cleanupFiles(rawAudioPath) from catch block in runJob()
— cleanupJobTmp handles TMP_DIR for YouTube, uploads survive
- Add cleanupUploadDir() on webhook success path
- Add retry-endpoint.test.ts with 9 tests covering:
- 404 for unknown job
- 409 for non-retryable status (done, pending)
- 200 for cancelled (retryable)
- 200 for failed YouTube job (existing behavior)
- 200 for failed upload-source job (new behavior, .webm and .mp3)
- Negative: retryJob not called on 404/409
- Add downloader.test.ts tests for saveUploadedFile persistent path,
getUploadPath, cleanupUploadDir, isolation, and non-existent cleanup
- Fix webhook.test.ts mock to include cleanupUploadDir
All 189 tests pass across 12 test files.
This commit is contained in:
@@ -8,9 +8,6 @@ export async function POST({ params }) {
|
||||
if (!['failed', 'cancelled'].includes(job.status)) {
|
||||
throw error(409, 'Only failed or cancelled jobs can be retried');
|
||||
}
|
||||
if (!job.source.startsWith('http')) {
|
||||
throw error(422, 'Cannot retry a file upload — please re-upload the file');
|
||||
}
|
||||
await retryJob(params.id);
|
||||
return json({ ok: true });
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { json, error } from '@sveltejs/kit';
|
||||
import { getJob, updateJob, setJobStatus } from '$lib/server/db.js';
|
||||
import { writeOutputs } from '$lib/server/formatter.js';
|
||||
import { sendNotification } from '$lib/server/push.js';
|
||||
import { cleanupJobTmp } from '$lib/server/downloader.js';
|
||||
import { cleanupJobTmp, cleanupUploadDir } from '$lib/server/downloader.js';
|
||||
import { emitProgress } from '$lib/server/pipeline.js';
|
||||
import type { Segment, WhisperJob } from '$lib/types.js';
|
||||
|
||||
@@ -79,6 +79,7 @@ export async function POST({ params, request }) {
|
||||
|
||||
await sendNotification(jobId, '✅ Transcript ready', job.title);
|
||||
await cleanupJobTmp(jobId);
|
||||
await cleanupUploadDir(jobId).catch(() => {});
|
||||
|
||||
return json({ ok: true });
|
||||
} catch (err: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user