diff --git a/server/utils/files/multer.js b/server/utils/files/multer.js index a4b90042e1d54e2bad4a31ec988c90eb204b8def..18c6df6079c704c374752162a82fbcf64a22feb0 100644 --- a/server/utils/files/multer.js +++ b/server/utils/files/multer.js @@ -2,6 +2,7 @@ const multer = require("multer"); const path = require("path"); const fs = require("fs"); const { v4 } = require("uuid"); +const { normalizePath } = require("."); /** * Handle File uploads for auto-uploading. @@ -16,8 +17,8 @@ const fileUploadStorage = multer.diskStorage({ cb(null, uploadOutput); }, filename: function (_, file, cb) { - file.originalname = Buffer.from(file.originalname, "latin1").toString( - "utf8" + file.originalname = normalizePath( + Buffer.from(file.originalname, "latin1").toString("utf8") ); cb(null, file.originalname); }, @@ -36,6 +37,7 @@ const fileAPIUploadStorage = multer.diskStorage({ cb(null, uploadOutput); }, filename: function (_, file, cb) { + file.originalname = normalizePath(file.originalname); cb(null, file.originalname); }, }); @@ -51,8 +53,8 @@ const assetUploadStorage = multer.diskStorage({ return cb(null, uploadOutput); }, filename: function (_, file, cb) { - file.originalname = Buffer.from(file.originalname, "latin1").toString( - "utf8" + file.originalname = normalizePath( + Buffer.from(file.originalname, "latin1").toString("utf8") ); cb(null, file.originalname); }, @@ -71,7 +73,9 @@ const pfpUploadStorage = multer.diskStorage({ return cb(null, uploadOutput); }, filename: function (req, file, cb) { - const randomFileName = `${v4()}${path.extname(file.originalname)}`; + const randomFileName = `${v4()}${path.extname( + normalizePath(file.originalname) + )}`; req.randomFileName = randomFileName; cb(null, randomFileName); },