collection added

This commit is contained in:
Jonathan Jara 2025-06-06 00:45:31 -07:00
parent 6546d84999
commit 8bf0b8d831

View File

@ -6,32 +6,24 @@ const path = require("path");
const authMiddleware = require('../../middleware/authMiddleware');
const storage = multer.diskStorage({
destination: function (req, file, cb) {
// Make sure this folder exists on disk: ./uploads/cars
destination: (req, file, cb) => {
cb(null, path.join(__dirname, "../../../uploads/cars"));
},
filename: function (req, file, cb) {
// Always give it a timestamp-based name + the correct extension
// (dont trust file.originalname if its a data:URI blob)
filename: (req, file, cb) => {
let ext = ".jpg";
if (file.mimetype === "image/png") {
ext = ".png";
} else if (file.mimetype === "image/jpeg") {
ext = ".jpg";
}
if (file.mimetype === "image/png") ext = ".png";
else if (file.mimetype === "image/jpeg") ext = ".jpg";
const uniqueName = `${Date.now()}${ext}`;
const uniqueName = Date.now() + ext;
cb(null, uniqueName);
},
});
const allowedMimeTypes = new Set(["image/jpeg", "image/png", "image/jpg"]);
const upload = multer({
storage: storage,
limits: {
fileSize: 5 * 1024 * 1024, // max 5 MB
},
export const upload = multer({
storage,
limits: { fileSize: 5 * 1024 * 1024 },
fileFilter: (req, file, cb) => {
if (!allowedMimeTypes.has(file.mimetype)) {
return cb(new Error("Only JPG/JPEG/PNG images are allowed"), false);