Refactor la gestion des vidéos pour utiliser une vidéo de secours en cas d'absence de fichier, améliorant ainsi la robustesse du service.

This commit is contained in:
2025-03-31 09:36:05 +02:00
parent 6747062f0b
commit 3849042869

View File

@@ -140,7 +140,8 @@ router.get('/videos/file/:video_id', (req, res) => {
fs.access(videoPath, fs.constants.F_OK, (err) => { fs.access(videoPath, fs.constants.F_OK, (err) => {
if (err) { if (err) {
console.error('Video file not found:', err); console.error('Video file not found:', err);
return serveFallbackVideo(res); videoPath = dbTester.getCatVideo();
// return res.status(404).json({ error: 'Video file not found' });
} }
const stat = fs.statSync(videoPath); const stat = fs.statSync(videoPath);
@@ -173,15 +174,8 @@ router.get('/videos/file/:video_id', (req, res) => {
}); });
}); });
function serveFallbackVideo(res) { function serveFallbackVideo() {
const videoPath = dbTester.getCatVideo(); return dbTester.getCatVideo();
fs.access(videoPath, fs.constants.F_OK, (err) => {
if (err) {
console.error('Fallback video not found:', err);
return res.status(500).json({ error: 'Fallback video not found' });
}
res.download(videoPath);
});
} }
router.get('/videos/progress/:video_id', async (req, res) => { router.get('/videos/progress/:video_id', async (req, res) => {