From 756a1b11b2deeb3d859c81a23a34a613daba82ae Mon Sep 17 00:00:00 2001 From: Sojabio Date: Wed, 11 Dec 2024 17:32:11 +0100 Subject: [PATCH] allow multiple images formats --- img/src/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/img/src/index.ts b/img/src/index.ts index 4fb351f..4decd88 100644 --- a/img/src/index.ts +++ b/img/src/index.ts @@ -8,15 +8,24 @@ const app = express(); const port = 4000; app.use(cors()); +const MIME_TYPES: Record = { + "image/jpg": "jpg", + "image/jpeg": "jpg", + "image/png": "png" +}; + + const storage = multer.diskStorage({ destination: function (_req, _file, cb) { cb(null, path.join(__dirname, "../uploads/")); }, filename: function (_req, file, cb) { - cb(null, Date.now() + "-" + file.originalname); + const extension = MIME_TYPES[file.mimetype]; + cb(null, Date.now() + '.' + extension); + }, }); -const upload = multer({ storage: storage }); +const upload = multer({ storage: storage }); app.get("/", (_req, res) => { res.send("Healthcheck Okay");