From 9ea4e895b46f537ced16ecea856d6a7c6e3a78f2 Mon Sep 17 00:00:00 2001 From: razzanYoni <13521087@mahasiswa.itb.ac.id> Date: Wed, 15 Nov 2023 17:06:09 +0700 Subject: [PATCH] rename multer --- src/utils/file-processing.ts | 39 +----------------------------------- src/utils/multer.ts | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 38 deletions(-) create mode 100644 src/utils/multer.ts diff --git a/src/utils/file-processing.ts b/src/utils/file-processing.ts index 897cc53..d124606 100644 --- a/src/utils/file-processing.ts +++ b/src/utils/file-processing.ts @@ -1,38 +1 @@ -import multer from "multer"; - -// https://github.com/expressjs/multer -const storage = multer.memoryStorage(); - -const uploadCover = multer({ - storage: storage, - limits: { - fileSize: 1024 * 1024 * 10 // 10MB - }, - fileFilter: function (req, file, cb) { - if (file.mimetype === "image/png" || file.mimetype === "image/jpeg" || file.mimetype === "image/jpg") { - cb(null, true) - } else { - cb(null, false) - return cb(new Error('Only .png, .jpg and .jpeg format allowed!')) - } - } -}); - -const uploadSong = multer({ - storage: storage, - limits: { - fileSize: 1024 * 1024 * 10 // 10MB - }, - fileFilter: function (req, file, cb) { - if (file.mimetype === "audio/mpeg") { - cb(null, true) - } else { - return cb(new Error('Only .mp3 format allowed!')) - } - } -}); - -export { - uploadCover, - uploadSong, -} \ No newline at end of file +// TODO : save file to local storage \ No newline at end of file diff --git a/src/utils/multer.ts b/src/utils/multer.ts new file mode 100644 index 0000000..897cc53 --- /dev/null +++ b/src/utils/multer.ts @@ -0,0 +1,38 @@ +import multer from "multer"; + +// https://github.com/expressjs/multer +const storage = multer.memoryStorage(); + +const uploadCover = multer({ + storage: storage, + limits: { + fileSize: 1024 * 1024 * 10 // 10MB + }, + fileFilter: function (req, file, cb) { + if (file.mimetype === "image/png" || file.mimetype === "image/jpeg" || file.mimetype === "image/jpg") { + cb(null, true) + } else { + cb(null, false) + return cb(new Error('Only .png, .jpg and .jpeg format allowed!')) + } + } +}); + +const uploadSong = multer({ + storage: storage, + limits: { + fileSize: 1024 * 1024 * 10 // 10MB + }, + fileFilter: function (req, file, cb) { + if (file.mimetype === "audio/mpeg") { + cb(null, true) + } else { + return cb(new Error('Only .mp3 format allowed!')) + } + } +}); + +export { + uploadCover, + uploadSong, +} \ No newline at end of file -- GitLab