const multer = require("multer");

// ✅ Pakai memoryStorage → file masuk ke RAM, ada file.buffer
const storage = multer.memoryStorage();

// ✅ Filter hanya image (jpg, jpeg, png, webp)
const fileFilter = (req, file, cb) => {
  const allowedTypes = ["image/jpeg", "image/jpg", "image/png", "image/webp"];
  if (allowedTypes.includes(file.mimetype)) {
    cb(null, true); // lolos
  } else {
    cb(new Error("Hanya file gambar yang diperbolehkan (jpg, jpeg, png, webp)"), false);
  }
};

const upload = multer({
  storage,
  fileFilter,
  limits: {
    fileSize: 100 * 1024 * 1024, 
  },
});

module.exports = upload;
