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:
Torsten Schulz (local)
2025-11-14 22:56:25 +01:00
parent 125ca6d7ce
commit 71ced31c1b
2 changed files with 5 additions and 83 deletions

View File

@@ -336,37 +336,19 @@ const formData = ref({
const loadResults = async () => {
try {
// Verwende API-Endpoint statt statische Datei, um Cache-Probleme zu vermeiden
const timestamp = new Date().getTime()
const response = await fetch(`/api/vereinsmeisterschaften?t=${timestamp}`, {
const response = await fetch('/api/vereinsmeisterschaften', {
cache: 'no-cache',
headers: {
'Cache-Control': 'no-cache'
}
})
console.log('=== FRONTEND LOAD DEBUG ===')
console.log('Load URL:', `/api/vereinsmeisterschaften?t=${timestamp}`)
console.log('Response Status:', response.status)
console.log('Response Headers - Content-Type:', response.headers.get('content-type'))
console.log('Response Headers - Cache-Control:', response.headers.get('cache-control'))
if (!response.ok) {
console.error('Fehler beim Laden - Response nicht OK:', response.status)
return
}
if (!response.ok) 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) {
console.log('Zu wenige Zeilen zum Parsen')
return
}
if (lines.length < 2) return
results.value = lines.slice(1).map(line => {
// CSV-Parser: Respektiert Anführungszeichen
@@ -399,9 +381,6 @@ 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)
}
@@ -684,13 +663,6 @@ 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',
@@ -703,16 +675,11 @@ 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 {
console.error('Fehler beim Speichern - Response nicht OK:', response.status, responseData)
const responseData = await response.json()
throw new Error('Fehler beim Speichern: ' + (responseData.message || response.statusText))
}
} catch (error) {