feat(mannschaften): split SUN columns and prepare seasonal team CSVs
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 2m40s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Has been skipped

This commit is contained in:
Torsten Schulz (local)
2026-05-20 17:45:14 +02:00
parent e19158558d
commit 2d42ef3ecd
3 changed files with 65 additions and 27 deletions

View File

@@ -51,8 +51,9 @@ export default defineEventHandler(async (event) => {
'termine.csv',
'spielplan.csv'
]
const isSeasonalMannschaftenFile = /^mannschaften_\d{2}--\d{2}\.csv$/.test(String(filename))
if (!allowedFiles.includes(filename)) {
if (!allowedFiles.includes(filename) && !isSeasonalMannschaftenFile) {
throw createError({
statusCode: 403,
statusMessage: 'Datei nicht erlaubt'
@@ -105,7 +106,9 @@ export default defineEventHandler(async (event) => {
'termine.csv': [`${cwd}/server/data/public-data/termine.csv`, `${cwd}/../server/data/public-data/termine.csv`],
'spielplan.csv': [`${cwd}/server/data/public-data/spielplan.csv`, `${cwd}/../server/data/public-data/spielplan.csv`]
}
const internalPaths = dataTargetsByFile[filename] || []
const internalPaths = isSeasonalMannschaftenFile
? [`${cwd}/server/data/public-data/${filename}`, `${cwd}/../server/data/public-data/${filename}`]
: (dataTargetsByFile[filename] || [])
const uniquePaths = [...new Set([...internalPaths])]
const writeResults = []

View File

@@ -1,5 +1,10 @@
import { promises as fs } from 'fs'
import path from 'path'
import { getCurrentSeasonSlug, validateSeasonSlug } from '../utils/spielplan-data.js'
function normalizeSeasonFilename(season) {
return `mannschaften_${season}.csv`
}
async function exists(p) {
try {
@@ -13,20 +18,36 @@ async function exists(p) {
export default defineEventHandler(async (event) => {
try {
const cwd = process.cwd()
const filename = 'mannschaften.csv'
const query = getQuery(event)
const requestedSeason = query.season ? String(query.season).trim() : ''
if (requestedSeason && !validateSeasonSlug(requestedSeason)) {
throw createError({
statusCode: 400,
statusMessage: 'Ungueltiger Saison-Slug'
})
}
const defaultSeason = getCurrentSeasonSlug()
const candidateFileNames = requestedSeason
? [normalizeSeasonFilename(requestedSeason), 'mannschaften.csv']
: [normalizeSeasonFilename(defaultSeason), 'mannschaften.csv']
// Prefer CMS write target first (server/data/public-data),
// then legacy locations.
const candidates = [
path.join(cwd, 'server/data/public-data', filename),
path.join(cwd, '../server/data/public-data', filename),
path.join(cwd, '.output/server/data', filename),
path.join(cwd, 'server/data', filename),
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)
]
const candidates = []
for (const filename of candidateFileNames) {
candidates.push(
path.join(cwd, 'server/data/public-data', filename),
path.join(cwd, '../server/data/public-data', filename),
path.join(cwd, '.output/server/data', filename),
path.join(cwd, 'server/data', filename),
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) {