import fs from 'fs';
import path from 'path';

export default function handler(req, res) {
  const filePath = path.join(process.cwd(), 'data', 'devlog.json');

  if (req.method === 'POST') {
    try {
      // Stelle sicher, dass jeder Eintrag ein content-Array hat
      const updatedData = req.body.map(entry => ({
        ...entry,
        content: entry.content || []
      }));
      
      fs.writeFileSync(filePath, JSON.stringify(updatedData, null, 2));
      res.status(200).json({ message: 'DevLog updated successfully!' });
    } catch (error) {
      res.status(500).json({ message: 'Error updating DevLog', error });
    }
  } else {
    res.status(405).json({ message: 'Method not allowed' });
  }
}
