feat: add PATCH /recorders/:id endpoint to edit recorder settings

Allows updating name, source_type, source_config, recording_codec,
recording_resolution, proxy_enabled, proxy_codec, proxy_resolution,
and project_id. Blocked while the recorder is actively recording.
This commit is contained in:
Zac Gaetano 2026-05-18 23:24:27 -04:00
parent 29b5910fff
commit a9ca7be1d5

View file

@ -187,6 +187,69 @@ router.get('/:id', async (req, res, next) => {
} }
}); });
// PATCH /:id - Edit recorder settings
// Blocked while recorder is actively recording to prevent config drift.
router.patch('/:id', async (req, res, next) => {
try {
const { id } = req.params;
const recorderResult = await pool.query(
'SELECT * FROM recorders WHERE id = $1',
[id]
);
if (recorderResult.rows.length === 0) {
return res.status(404).json({ error: 'Recorder not found' });
}
const recorder = recorderResult.rows[0];
if (recorder.status === 'recording') {
return res.status(409).json({ error: 'Cannot edit a recorder while it is recording — stop it first' });
}
const {
name,
source_type,
source_config,
recording_codec,
recording_resolution,
proxy_enabled,
proxy_codec,
proxy_resolution,
project_id,
} = req.body;
const updates = [];
const params = [];
let n = 1;
if (name !== undefined) { updates.push(`name = $${n++}`); params.push(name); }
if (source_type !== undefined) { updates.push(`source_type = $${n++}`); params.push(source_type); }
if (source_config !== undefined) { updates.push(`source_config = $${n++}`); params.push(source_config); }
if (recording_codec !== undefined) { updates.push(`recording_codec = $${n++}`); params.push(recording_codec); }
if (recording_resolution !== undefined){ updates.push(`recording_resolution = $${n++}`); params.push(recording_resolution); }
if (proxy_enabled !== undefined) { updates.push(`proxy_enabled = $${n++}`); params.push(proxy_enabled); }
if (proxy_codec !== undefined) { updates.push(`proxy_codec = $${n++}`); params.push(proxy_codec); }
if (proxy_resolution !== undefined) { updates.push(`proxy_resolution = $${n++}`); params.push(proxy_resolution); }
if (project_id !== undefined) { updates.push(`project_id = $${n++}`); params.push(project_id || null); }
if (updates.length === 0) {
return res.status(400).json({ error: 'No fields to update' });
}
updates.push(`updated_at = NOW()`);
params.push(id);
const result = await pool.query(
`UPDATE recorders SET ${updates.join(', ')} WHERE id = $${n} RETURNING *`,
params
);
res.json(result.rows[0]);
} catch (err) {
next(err);
}
});
// POST /:id/start - Start recording // POST /:id/start - Start recording
router.post('/:id/start', async (req, res, next) => { router.post('/:id/start', async (req, res, next) => {
try { try {