From 323669c4ef54f7d8d2817a78d025c12540d71d32 Mon Sep 17 00:00:00 2001 From: Kerboul Date: Wed, 8 Jan 2025 16:10:16 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20route=20API=20pour=20r=C3=A9cup?= =?UTF-8?q?=C3=A9rer=20une=20image=20avec=20gestion=20des=20erreurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/api.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/routes/api.js b/routes/api.js index 2ab2eae..5ea0036 100644 --- a/routes/api.js +++ b/routes/api.js @@ -351,4 +351,30 @@ router.delete('/videos/:id', (req, res) => { }); }); +// Test Image +/** + * @swagger + * /smile: + * get: + * description: Use to request the smile image + * responses: + * 200: + * description: A successful response + * 404: + * description: Image not found + */ +router.get('/smile', (req, res) => { + res.setHeader('Access-Control-Allow-Origin', 'http://localhost:5500'); + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE'); + res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); + const imagePath = path.join('/storage/smile.jpg'); + fs.access(imagePath, fs.constants.F_OK, (err) => { + if (err) { + console.error('Image not found:', err); + return res.status(404).json({ error: 'Image not found' }); + } + res.sendFile(imagePath); + }); +}); + module.exports = router;