Admin Panel storage fixed

This commit is contained in:
michi 2025-08-26 14:57:26 +02:00
parent de231cdf5e
commit bb5e50a775
6 changed files with 77 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View File

@ -2,5 +2,6 @@
"/_app": "pages/_app.js", "/_app": "pages/_app.js",
"/_error": "pages/_error.js", "/_error": "pages/_error.js",
"/_document": "pages/_document.js", "/_document": "pages/_document.js",
"/admin/login": "pages/admin/login.js" "/admin/login": "pages/admin/login.js",
"/api/auth": "pages/api/auth.js"
} }

File diff suppressed because one or more lines are too long

View File

@ -2,22 +2,71 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
export default function handler(req, res) { export default function handler(req, res) {
console.log('API /update-devlog aufgerufen');
console.log('Request method:', req.method);
console.log('Request body:', JSON.stringify(req.body, null, 2));
const filePath = path.join(process.cwd(), 'data', 'devlog.json'); const filePath = path.join(process.cwd(), 'data', 'devlog.json');
console.log('File path:', filePath);
if (req.method === 'POST') { if (req.method === 'POST') {
try { try {
// Stelle sicher, dass jeder Eintrag ein content-Array hat // Validiere eingehende Daten
const updatedData = req.body.map(entry => ({ if (!req.body) {
...entry, console.error('Fehler: Kein Request Body vorhanden');
content: entry.content || [] return res.status(400).json({ message: 'Kein Request Body vorhanden' });
})); }
if (!Array.isArray(req.body)) {
console.error('Fehler: Request Body ist kein Array');
return res.status(400).json({ message: 'Request Body muss ein Array sein' });
}
console.log('Anzahl der Einträge:', req.body.length);
// Prüfe Dateiberechtigungen
try {
fs.accessSync(path.dirname(filePath), fs.constants.W_OK);
console.log('Schreibberechtigung für Verzeichnis vorhanden');
} catch (permError) {
console.error('Fehler: Keine Schreibberechtigung für Verzeichnis:', permError.message);
return res.status(500).json({ message: 'Keine Schreibberechtigung für Verzeichnis', error: permError.message });
}
// Stelle sicher, dass jeder Eintrag ein content-Array hat
const updatedData = req.body.map((entry, index) => {
console.log(`Verarbeite Eintrag ${index}:`, entry);
// Validiere erforderliche Felder
if (!entry.title || !entry.date) {
console.error(`Fehler: Eintrag ${index} fehlen erforderliche Felder (title oder date)`);
throw new Error(`Eintrag ${index} fehlen erforderliche Felder`);
}
return {
...entry,
content: entry.content || []
};
});
console.log('Verarbeitete Daten:', JSON.stringify(updatedData, null, 2));
// Schreibe Datei
fs.writeFileSync(filePath, JSON.stringify(updatedData, null, 2), 'utf8');
console.log('Datei erfolgreich geschrieben');
fs.writeFileSync(filePath, JSON.stringify(updatedData, null, 2));
res.status(200).json({ message: 'DevLog updated successfully!' }); res.status(200).json({ message: 'DevLog updated successfully!' });
} catch (error) { } catch (error) {
res.status(500).json({ message: 'Error updating DevLog', error }); console.error('Fehler beim Verarbeiten der Anfrage:', error);
console.error('Error stack:', error.stack);
res.status(500).json({
message: 'Error updating DevLog',
error: error.message,
stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
});
} }
} else { } else {
console.log('Methode nicht erlaubt:', req.method);
res.status(405).json({ message: 'Method not allowed' }); res.status(405).json({ message: 'Method not allowed' });
} }
} }