Enhance CSV loading and saving functionality with detailed debugging logs in 'vereinsmeisterschaften.vue' and 'save-csv.post.js'. Implement cache-busting for fetching CSV data and improve error handling during file operations, ensuring better traceability and reliability in data management.

This commit is contained in:
Torsten Schulz (local)
2025-11-14 22:31:55 +01:00
parent c6b66ad19c
commit 1c8ccbb92c
2 changed files with 91 additions and 5 deletions

View File

@@ -57,17 +57,62 @@ export default defineEventHandler(async (event) => {
filePath = path.join(cwd, 'public/data', filename)
}
// Debugging: Zeige Pfad-Informationen
const absoluteFilePath = path.resolve(filePath)
console.log('=== CSV SAVE DEBUG ===')
console.log('filename:', filename)
console.log('process.cwd():', cwd)
console.log('calculated filePath:', filePath)
console.log('absolute filePath:', absoluteFilePath)
console.log('content length:', content.length)
console.log('content preview (first 200 chars):', content.substring(0, 200))
const dataDir = path.dirname(filePath)
// Sicherstellen, dass das Verzeichnis existiert
await fs.mkdir(dataDir, { recursive: true })
console.log('dataDir exists/created:', dataDir)
// Prüfe ob Datei existiert vor dem Schreiben
try {
const statsBefore = await fs.stat(absoluteFilePath)
console.log('Datei existiert vor Schreiben:', true)
console.log('Dateigröße vor Schreiben:', statsBefore.size, 'bytes')
console.log('Letzte Änderung vor Schreiben:', statsBefore.mtime)
} catch (error) {
console.log('Datei existiert nicht vor Schreiben:', error.code)
}
// Datei schreiben
await fs.writeFile(filePath, content, 'utf8')
console.log('Datei geschrieben:', absoluteFilePath)
// Prüfe ob Datei existiert nach dem Schreiben
try {
const statsAfter = await fs.stat(absoluteFilePath)
console.log('Datei existiert nach Schreiben:', true)
console.log('Dateigröße nach Schreiben:', statsAfter.size, 'bytes')
console.log('Letzte Änderung nach Schreiben:', statsAfter.mtime)
// Lese die Datei zurück, um zu bestätigen, dass sie geschrieben wurde
const writtenContent = await fs.readFile(absoluteFilePath, 'utf8')
console.log('Geschriebener Inhalt (first 200 chars):', writtenContent.substring(0, 200))
console.log('Geschriebener Inhalt length:', writtenContent.length)
console.log('Inhalte stimmen überein:', writtenContent === content ? 'JA' : 'NEIN')
} catch (error) {
console.error('FEHLER: Datei existiert nicht nach Schreiben:', error)
}
console.log('=== END CSV SAVE DEBUG ===')
return {
success: true,
message: 'Datei erfolgreich gespeichert'
message: 'Datei erfolgreich gespeichert',
debug: {
filePath: absoluteFilePath,
cwd: cwd,
contentLength: content.length
}
}
} catch (error) {