Refactor CSV loading and saving in 'vereinsmeisterschaften.vue' and 'save-csv.post.js' by removing extensive debugging logs to streamline code. Improve error handling during data fetching and file writing processes for enhanced reliability and maintainability.
This commit is contained in:
@@ -57,62 +57,17 @@ 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',
|
||||
debug: {
|
||||
filePath: absoluteFilePath,
|
||||
cwd: cwd,
|
||||
contentLength: content.length
|
||||
}
|
||||
message: 'Datei erfolgreich gespeichert'
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user