From 8f69705ae9a7a6cdf44e9d875fb18a425cd2492f Mon Sep 17 00:00:00 2001 From: dakerboul Date: Mon, 10 Mar 2025 16:54:13 +0100 Subject: [PATCH] =?UTF-8?q?Modifier=20la=20route=20de=20t=C3=A9l=C3=A9char?= =?UTF-8?q?gement=20de=20vid=C3=A9o=20pour=20v=C3=A9rifier=20l'existence?= =?UTF-8?q?=20du=20fichier=20avant=20de=20le=20t=C3=A9l=C3=A9charger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/videoRoutes.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/routes/videoRoutes.js b/routes/videoRoutes.js index 2a14081..511778e 100644 --- a/routes/videoRoutes.js +++ b/routes/videoRoutes.js @@ -270,17 +270,13 @@ router.get('/videos/file/:video_id', (req, res) => { return res.status(400).json({ error: 'Video not yet produced' }); } const videoPath = video.video_file; - 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' }); + 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); }); }); });