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:
@@ -270,13 +270,17 @@ 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;
|
||||||
console.log('Video path:', videoPath);
|
const fileStream = fs.createReadStream(videoPath);
|
||||||
fs.access(videoPath, fs.constants.F_OK, (err) => {
|
|
||||||
if (err) {
|
res.writeHead(200, {
|
||||||
console.error('Video not found:', err);
|
'Content-Type': 'video/mp4',
|
||||||
return res.status(404).json({ error: 'Video not found' });
|
'Content-Disposition': `attachment; filename="${path.basename(videoPath)}"`
|
||||||
}
|
});
|
||||||
res.download(videoPath);
|
fileStream.pipe(res);
|
||||||
|
|
||||||
|
fileStream.on('error', (err) => {
|
||||||
|
console.error('File stream error:', err);
|
||||||
|
res.status(500).json({ error: 'Error streaming video' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user