diff --git a/package.json b/package.json index 6315d75..b659bdb 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "dependencies": { "axios": "^0.25.0", "express": "^4.17.2", + "path": "^0.12.7", "sharp": "^0.29.3" } } diff --git a/src/routes/api/image.ts b/src/routes/api/image.ts index 491f940..450350e 100644 --- a/src/routes/api/image.ts +++ b/src/routes/api/image.ts @@ -1,10 +1,26 @@ import express from "express" +import path from "path" +import fs from "fs" const image = express.Router(); -image.get('/', (req, res) => { - res.send('Welcome to image route please add parametres in the url'); +image.get('/', + async (req: express.Request, res: express.Response): Promise => { + let filename = req.query.filename as string; -}) + try { + let filePath = path.resolve("images/full", `${filename}.jpg`); + console.log('FILE PATH', filePath); + if (!fs.existsSync(filePath)) { + res.status(404).send("Image don't exist! Try another name"); + return; + } + res.sendFile(filePath); + } catch (err) { + res.status(404).send(`An error occured`); + } + + //res.send('Welcome to image route please add parametres in the url'); + }) export default image; \ No newline at end of file