Update CSV data fetching to use API endpoint in Mannschaften components
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 5s

This commit modifies the loadMannschaften function across multiple components to fetch CSV data from the new API endpoint '/api/mannschaften' instead of the previous static file path '/data/mannschaften.csv'. This change enhances data retrieval consistency and aligns with the updated data management strategy in the application.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 08:28:43 +01:00
parent 27312cc118
commit c39e5de29f
6 changed files with 63 additions and 5 deletions

View File

@@ -0,0 +1,58 @@
import { promises as fs } from 'fs'
import path from 'path'
async function exists(p) {
try {
await fs.access(p)
return true
} catch {
return false
}
}
export default defineEventHandler(async (event) => {
try {
const cwd = process.cwd()
const filename = 'mannschaften.csv'
const candidates = [
path.join(cwd, '.output/public/data', filename),
path.join(cwd, 'public/data', filename),
path.join(cwd, '../.output/public/data', filename),
path.join(cwd, '../public/data', filename)
]
let csvPath = null
for (const p of candidates) {
// eslint-disable-next-line no-await-in-loop
if (await exists(p)) {
csvPath = p
break
}
}
if (!csvPath) {
throw createError({
statusCode: 404,
statusMessage: 'Mannschaften-Datei nicht gefunden'
})
}
const csv = await fs.readFile(csvPath, 'utf-8')
setHeader(event, 'Content-Type', 'text/csv; charset=utf-8')
setHeader(event, 'Cache-Control', 'no-cache, no-store, must-revalidate')
setHeader(event, 'Pragma', 'no-cache')
setHeader(event, 'Expires', '0')
return csv
} catch (error) {
if (error?.statusCode) throw error
console.error('Fehler beim Laden der Mannschaften:', error)
throw createError({
statusCode: 500,
statusMessage: 'Fehler beim Laden der Mannschaften'
})
}
})