From d2549f097b56c4f9d34f95a5ffb65c8188ca2eae Mon Sep 17 00:00:00 2001 From: Kerboul Date: Thu, 24 Oct 2024 17:03:26 +0200 Subject: [PATCH] update api.js --- routes/api.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/routes/api.js b/routes/api.js index f63686d..6572c49 100644 --- a/routes/api.js +++ b/routes/api.js @@ -3,6 +3,8 @@ const express = require('express'); const router = express.Router(); const db = require('../db'); // Assurez-vous d'importer le fichier db.js +const path = require('path'); +const fs = require('fs'); /** * @swagger @@ -288,4 +290,26 @@ router.post('/delete', (req, res) => { }); }); +/** + * @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) => { + const imagePath = path.join(__dirname, '../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;