Modifier la route de téléchargement de vidéo pour utiliser un flux de fichiers et gérer les erreurs de streaming

This commit is contained in:
2025-03-10 16:49:33 +01:00
parent 37d82d1133
commit 5979cded02

View File

@@ -270,13 +270,17 @@ router.get('/videos/file/:video_id', (req, res) => {
return res.status(400).json({ error: 'Video not yet produced' });
}
const videoPath = video.video_file;
console.log('Video path:', videoPath);
fs.access(videoPath, fs.constants.F_OK, (err) => {
if (err) {
console.error('Video not found:', err);
return res.status(404).json({ error: 'Video not found' });
}
res.download(videoPath);
const fileStream = fs.createReadStream(videoPath);
res.writeHead(200, {
'Content-Type': 'video/mp4',
'Content-Disposition': `attachment; filename="${path.basename(videoPath)}"`
});
fileStream.pipe(res);
fileStream.on('error', (err) => {
console.error('File stream error:', err);
res.status(500).json({ error: 'Error streaming video' });
});
});
});