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:
@@ -335,13 +335,38 @@ const formData = ref({
|
|||||||
|
|
||||||
const loadResults = async () => {
|
const loadResults = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/data/vereinsmeisterschaften.csv')
|
// Cache-Busting: Füge Timestamp hinzu, um sicherzustellen, dass wir die neueste Version laden
|
||||||
if (!response.ok) return
|
const timestamp = new Date().getTime()
|
||||||
|
const response = await fetch(`/data/vereinsmeisterschaften.csv?t=${timestamp}`, {
|
||||||
|
cache: 'no-cache',
|
||||||
|
headers: {
|
||||||
|
'Cache-Control': 'no-cache'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('=== FRONTEND LOAD DEBUG ===')
|
||||||
|
console.log('Load URL:', `/data/vereinsmeisterschaften.csv?t=${timestamp}`)
|
||||||
|
console.log('Response Status:', response.status)
|
||||||
|
console.log('Response Headers - Last-Modified:', response.headers.get('last-modified'))
|
||||||
|
console.log('Response Headers - ETag:', response.headers.get('etag'))
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error('Fehler beim Laden - Response nicht OK:', response.status)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const csv = await response.text()
|
const csv = await response.text()
|
||||||
const lines = csv.split('\n').filter(line => line.trim() !== '')
|
console.log('CSV Content Länge:', csv.length)
|
||||||
|
console.log('CSV Content Preview (first 300 chars):', csv.substring(0, 300))
|
||||||
|
console.log('CSV Content Preview (last 200 chars):', csv.substring(csv.length - 200))
|
||||||
|
|
||||||
if (lines.length < 2) return
|
const lines = csv.split('\n').filter(line => line.trim() !== '')
|
||||||
|
console.log('Anzahl Zeilen:', lines.length)
|
||||||
|
|
||||||
|
if (lines.length < 2) {
|
||||||
|
console.log('Zu wenige Zeilen zum Parsen')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
results.value = lines.slice(1).map(line => {
|
results.value = lines.slice(1).map(line => {
|
||||||
// CSV-Parser: Respektiert Anführungszeichen
|
// CSV-Parser: Respektiert Anführungszeichen
|
||||||
@@ -374,6 +399,9 @@ const loadResults = async () => {
|
|||||||
bemerkung: values[5].trim()
|
bemerkung: values[5].trim()
|
||||||
}
|
}
|
||||||
}).filter(result => result !== null)
|
}).filter(result => result !== null)
|
||||||
|
|
||||||
|
console.log('Anzahl geladener Ergebnisse:', results.value.length)
|
||||||
|
console.log('=== END FRONTEND LOAD DEBUG ===')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fehler beim Laden der Vereinsmeisterschaften:', error)
|
console.error('Fehler beim Laden der Vereinsmeisterschaften:', error)
|
||||||
}
|
}
|
||||||
@@ -656,6 +684,13 @@ const save = async () => {
|
|||||||
|
|
||||||
const csvContent = [csvHeader, ...csvRows].join('\n')
|
const csvContent = [csvHeader, ...csvRows].join('\n')
|
||||||
|
|
||||||
|
// Frontend Debugging
|
||||||
|
console.log('=== FRONTEND SAVE DEBUG ===')
|
||||||
|
console.log('Anzahl Ergebnisse zum Speichern:', results.value.length)
|
||||||
|
console.log('CSV Content Länge:', csvContent.length)
|
||||||
|
console.log('CSV Content Preview (first 300 chars):', csvContent.substring(0, 300))
|
||||||
|
console.log('CSV Content Preview (last 200 chars):', csvContent.substring(csvContent.length - 200))
|
||||||
|
|
||||||
// CSV speichern
|
// CSV speichern
|
||||||
const response = await fetch('/api/cms/save-csv', {
|
const response = await fetch('/api/cms/save-csv', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -668,11 +703,17 @@ const save = async () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const responseData = await response.json()
|
||||||
|
console.log('Response Status:', response.status)
|
||||||
|
console.log('Response Data:', responseData)
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
console.log('=== END FRONTEND SAVE DEBUG ===')
|
||||||
// Erfolgreich gespeichert - keine weitere Nachricht bei automatischem Speichern
|
// Erfolgreich gespeichert - keine weitere Nachricht bei automatischem Speichern
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Fehler beim Speichern')
|
console.error('Fehler beim Speichern - Response nicht OK:', response.status, responseData)
|
||||||
|
throw new Error('Fehler beim Speichern: ' + (responseData.message || response.statusText))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fehler beim Speichern:', error)
|
console.error('Fehler beim Speichern:', error)
|
||||||
|
|||||||
@@ -57,17 +57,62 @@ export default defineEventHandler(async (event) => {
|
|||||||
filePath = path.join(cwd, 'public/data', filename)
|
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)
|
const dataDir = path.dirname(filePath)
|
||||||
|
|
||||||
// Sicherstellen, dass das Verzeichnis existiert
|
// Sicherstellen, dass das Verzeichnis existiert
|
||||||
await fs.mkdir(dataDir, { recursive: true })
|
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
|
// Datei schreiben
|
||||||
await fs.writeFile(filePath, content, 'utf8')
|
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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Datei erfolgreich gespeichert'
|
message: 'Datei erfolgreich gespeichert',
|
||||||
|
debug: {
|
||||||
|
filePath: absoluteFilePath,
|
||||||
|
cwd: cwd,
|
||||||
|
contentLength: content.length
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user