const multer = require("multer");
const path = require("path");
const fs = require("fs");

// 🔑 Zielordner: public/images
const uploadDir = path.join(__dirname, "../public/images");

// Ordner sicherstellen
if (!fs.existsSync(uploadDir)) {
  fs.mkdirSync(uploadDir, { recursive: true });
}

const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, uploadDir);
  },
  filename: (req, file, cb) => {
    // immer gleicher Name
    cb(null, "logo" + path.extname(file.originalname));
  }
});

module.exports = multer({ storage });

