diff --git a/src/utils/file-processing.ts b/src/utils/file-processing.ts index 897cc537addedef78729138a493744817b47f73c..d12460675c2d37c9993ce0b2fc0d986b19d50c83 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 0000000000000000000000000000000000000000..897cc537addedef78729138a493744817b47f73c --- /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