feat(audio): wire audio converters and bitrate validation into app.js/worker.js
This commit is contained in:
@@ -445,3 +445,85 @@ describe('POST /api/jobs — archives', () => {
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/jobs — audio', () => {
|
||||
it('creates a pending job converting a wav upload to mp3 with a valid bitrate', async () => {
|
||||
const fixturePath = path.join(config.storageDir, 'clip.wav');
|
||||
// Minimal RIFF/WAVE header: 'RIFF' + 4-byte size (unchecked) + 'WAVE'.
|
||||
await fs.writeFile(fixturePath, Buffer.concat([Buffer.from('RIFF'), Buffer.alloc(4), Buffer.from('WAVE')]));
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['mp3']))
|
||||
.field('qualities', JSON.stringify([192]))
|
||||
.attach('files', fixturePath, 'clip.wav');
|
||||
|
||||
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('wav');
|
||||
expect(job.targetFormat).toBe('mp3');
|
||||
expect(job.family).toBe('audio');
|
||||
expect(job.quality).toBe(192);
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
|
||||
it('rejects a bitrate outside the fixed chip set for an mp3 target', async () => {
|
||||
const fixturePath = path.join(config.storageDir, 'bad-bitrate.wav');
|
||||
await fs.writeFile(fixturePath, Buffer.concat([Buffer.from('RIFF'), Buffer.alloc(4), Buffer.from('WAVE')]));
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['mp3']))
|
||||
.field('qualities', JSON.stringify([200]))
|
||||
.attach('files', fixturePath, 'bad-bitrate.wav');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
|
||||
it('rejects a quality value for a flac target (lossless, no bitrate control)', async () => {
|
||||
const fixturePath = path.join(config.storageDir, 'to-flac.wav');
|
||||
await fs.writeFile(fixturePath, Buffer.concat([Buffer.from('RIFF'), Buffer.alloc(4), Buffer.from('WAVE')]));
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['flac']))
|
||||
.field('qualities', JSON.stringify([192]))
|
||||
.attach('files', fixturePath, 'to-flac.wav');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].error).toMatch(/Invalid quality/);
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
|
||||
it('creates a pending job converting flac to wav with no quality value', async () => {
|
||||
const fixturePath = path.join(config.storageDir, 'clip.flac');
|
||||
await fs.writeFile(fixturePath, Buffer.from('fLaC'));
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['wav']))
|
||||
.attach('files', fixturePath, 'clip.flac');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
|
||||
expect(job.sourceFormat).toBe('flac');
|
||||
expect(job.targetFormat).toBe('wav');
|
||||
expect(job.quality).toBeNull();
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
|
||||
it('lists the other 5 audio formats as targets for mp3, and never lists mp3 as its own target', async () => {
|
||||
const response = await request(app).get('/api/formats').query({ source: 'mp3' });
|
||||
|
||||
expect(response.body.targets).toEqual(expect.arrayContaining(['wav', 'ogg', 'flac', 'aac', 'm4a']));
|
||||
expect(response.body.targets).not.toContain('mp3');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user