Refactor la route de rendu vidéo pour utiliser async/await et améliorer la gestion des erreurs
This commit is contained in:
@@ -301,39 +301,40 @@ router.get('/videos/file/:video_id', (req, res) => {
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.post('/videos/render/:video_id', (req, res) => {
|
||||
router.post('/videos/render/:video_id', async (req, res) => {
|
||||
const videoId = req.params.video_id;
|
||||
const query = 'SELECT measurement_ids, project_id FROM public.videos WHERE id = $1';
|
||||
db.query(query, [videoId], (err, results) => {
|
||||
|
||||
db.query(query, [videoId], async (err, results) => {
|
||||
if (err) {
|
||||
return serverError.sendError('Error getting video:', res, err);
|
||||
}
|
||||
if (results.rows.length === 0) {
|
||||
return res.status(404).json({ error: 'Video not found' });
|
||||
}
|
||||
|
||||
const measurementIds = results.rows[0].measurement_ids;
|
||||
const project_id = results.rows[0].project_id;
|
||||
console.log('Measurement IDs:', measurementIds);
|
||||
console.log('Project ID:', project_id);
|
||||
const pathList = measureManager.getPathList(measurementIds, project_id).then(pathList => {
|
||||
console.log('Path list:', pathList);
|
||||
res.json({ message: 'Render process started' });
|
||||
const videoFile = videoManager.createVideoWithList(project_id, pathList);
|
||||
console.log('Video file:', videoFile);
|
||||
|
||||
try {
|
||||
videoManager.updateVideoFile(videoId, videoFile);
|
||||
const pathList = await measureManager.getPathList(measurementIds, project_id);
|
||||
console.log('Path list:', pathList);
|
||||
res.json({ message: 'Render process started' });
|
||||
|
||||
const videoFile = await videoManager.createVideoWithList(project_id, pathList);
|
||||
console.log('Video file:', videoFile);
|
||||
|
||||
await videoManager.updateVideoFile(videoId, videoFile);
|
||||
} catch (err) {
|
||||
console.error('Error updating video file:', err);
|
||||
res.status(500).json({ error: 'Error updating video file' });
|
||||
console.error('Error during video rendering:', err);
|
||||
res.status(500).json({ error: 'Error during video rendering' });
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('Error getting path list:', err);
|
||||
res.status(500).json({ error: 'Error getting path list' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /cat:
|
||||
|
||||
Reference in New Issue
Block a user