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 () => {
|
||||
try {
|
||||
const response = await fetch('/data/vereinsmeisterschaften.csv')
|
||||
if (!response.ok) return
|
||||
// Cache-Busting: Füge Timestamp hinzu, um sicherzustellen, dass wir die neueste Version laden
|
||||
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()
|
||||
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))
|
||||
|
||||
const lines = csv.split('\n').filter(line => line.trim() !== '')
|
||||
console.log('Anzahl Zeilen:', lines.length)
|
||||
|
||||
if (lines.length < 2) return
|
||||
if (lines.length < 2) {
|
||||
console.log('Zu wenige Zeilen zum Parsen')
|
||||
return
|
||||
}
|
||||
|
||||
results.value = lines.slice(1).map(line => {
|
||||
// CSV-Parser: Respektiert Anführungszeichen
|
||||
@@ -374,6 +399,9 @@ const loadResults = async () => {
|
||||
bemerkung: values[5].trim()
|
||||
}
|
||||
}).filter(result => result !== null)
|
||||
|
||||
console.log('Anzahl geladener Ergebnisse:', results.value.length)
|
||||
console.log('=== END FRONTEND LOAD DEBUG ===')
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Vereinsmeisterschaften:', error)
|
||||
}
|
||||
@@ -656,6 +684,13 @@ const save = async () => {
|
||||
|
||||
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
|
||||
const response = await fetch('/api/cms/save-csv', {
|
||||
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) {
|
||||
console.log('=== END FRONTEND SAVE DEBUG ===')
|
||||
// Erfolgreich gespeichert - keine weitere Nachricht bei automatischem Speichern
|
||||
return true
|
||||
} 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) {
|
||||
console.error('Fehler beim Speichern:', error)
|
||||
|
||||
Reference in New Issue
Block a user