Modifier la route de téléchargement de vidéo pour vérifier l'existence du fichier avant de le télécharger

This commit is contained in:
2025-03-10 16:54:13 +01:00
parent 5979cded02
commit 8f69705ae9

View File

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