Admin Panel storage fixed
This commit is contained in:
parent
de231cdf5e
commit
bb5e50a775
BIN
.next/cache/webpack/client-development/1.pack.gz
vendored
BIN
.next/cache/webpack/client-development/1.pack.gz
vendored
Binary file not shown.
BIN
.next/cache/webpack/client-development/2.pack.gz
vendored
BIN
.next/cache/webpack/client-development/2.pack.gz
vendored
Binary file not shown.
Binary file not shown.
@ -2,5 +2,6 @@
|
||||
"/_app": "pages/_app.js",
|
||||
"/_error": "pages/_error.js",
|
||||
"/_document": "pages/_document.js",
|
||||
"/admin/login": "pages/admin/login.js"
|
||||
"/admin/login": "pages/admin/login.js",
|
||||
"/api/auth": "pages/api/auth.js"
|
||||
}
|
||||
19
.next/trace
19
.next/trace
File diff suppressed because one or more lines are too long
@ -2,22 +2,71 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
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');
|
||||
console.log('File path:', filePath);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
try {
|
||||
// Stelle sicher, dass jeder Eintrag ein content-Array hat
|
||||
const updatedData = req.body.map(entry => ({
|
||||
...entry,
|
||||
content: entry.content || []
|
||||
}));
|
||||
// Validiere eingehende Daten
|
||||
if (!req.body) {
|
||||
console.error('Fehler: Kein Request Body vorhanden');
|
||||
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!' });
|
||||
} 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 {
|
||||
console.log('Methode nicht erlaubt:', req.method);
|
||||
res.status(405).json({ message: 'Method not allowed' });
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user