feat(video): wire video converters, resolution validation, and timeout into app.js/worker.js

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 22:01:58 +02:00
co-authored by Claude Sonnet 5
parent 9c1f857398
commit 457913d8d4
4 changed files with 121 additions and 1 deletions
+72
View File
@@ -527,3 +527,75 @@ describe('POST /api/jobs — audio', () => {
expect(response.body.targets).not.toContain('mp3');
});
});
describe('POST /api/jobs — video', () => {
it('creates a pending job converting an mp4 upload to webm with a valid resolution', async () => {
const fixturePath = path.join(config.storageDir, 'clip.mp4');
await fs.writeFile(
fixturePath,
Buffer.concat([Buffer.from([0, 0, 0, 0x18]), Buffer.from('ftyp'), Buffer.from('isom')])
);
const response = await request(app)
.post('/api/jobs')
.field('targetFormats', JSON.stringify(['webm']))
.field('qualities', JSON.stringify([720]))
.attach('files', fixturePath, 'clip.mp4');
expect(response.status).toBe(201);
expect(response.body.jobs[0].status).toBe('pending');
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
expect(job.sourceFormat).toBe('mp4');
expect(job.targetFormat).toBe('webm');
expect(job.family).toBe('video');
expect(job.quality).toBe(720);
await fs.unlink(fixturePath);
});
it('creates a pending job with no quality value (original resolution)', async () => {
const fixturePath = path.join(config.storageDir, 'clip-original.mp4');
await fs.writeFile(
fixturePath,
Buffer.concat([Buffer.from([0, 0, 0, 0x18]), Buffer.from('ftyp'), Buffer.from('isom')])
);
const response = await request(app)
.post('/api/jobs')
.field('targetFormats', JSON.stringify(['mkv']))
.attach('files', fixturePath, 'clip-original.mp4');
expect(response.status).toBe(201);
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
expect(job.quality).toBeNull();
await fs.unlink(fixturePath);
});
it('rejects a resolution outside the fixed 480/720/1080 set', async () => {
const fixturePath = path.join(config.storageDir, 'bad-resolution.mp4');
await fs.writeFile(
fixturePath,
Buffer.concat([Buffer.from([0, 0, 0, 0x18]), Buffer.from('ftyp'), Buffer.from('isom')])
);
const response = await request(app)
.post('/api/jobs')
.field('targetFormats', JSON.stringify(['webm']))
.field('qualities', JSON.stringify([360]))
.attach('files', fixturePath, 'bad-resolution.mp4');
expect(response.status).toBe(201);
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
await fs.unlink(fixturePath);
});
it('lists the other 4 video formats as targets for mp4, and never lists mp4 as its own target', async () => {
const response = await request(app).get('/api/formats').query({ source: 'mp4' });
expect(response.body.targets).toEqual(expect.arrayContaining(['webm', 'mov', 'avi', 'mkv']));
expect(response.body.targets).not.toContain('mp4');
});
});