|
|
|
|
@@ -75,6 +75,26 @@ function seasonSlugToLabel(slug) {
|
|
|
|
|
return `20${match[1]}/${match[2]}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function logReadError(message, filePath, error) {
|
|
|
|
|
console.error(message, { filePath, error })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function requireSeasonSlug(seasonSlug) {
|
|
|
|
|
const value = String(seasonSlug || '')
|
|
|
|
|
if (!SEASON_SLUG_PATTERN.test(value)) {
|
|
|
|
|
throw new Error(`Ungueltiger Spielplan-Saison-Slug: ${value}`)
|
|
|
|
|
}
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function normalizeSpielplanCsvPath(csvPath) {
|
|
|
|
|
const value = String(csvPath || '')
|
|
|
|
|
if (value.includes('\0') || path.basename(value) !== 'spielplan.csv') {
|
|
|
|
|
throw new Error('Ungueltiger Spielplan-CSV-Pfad')
|
|
|
|
|
}
|
|
|
|
|
return path.normalize(value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getCurrentSeasonSlug(date = new Date()) {
|
|
|
|
|
const year = date.getFullYear()
|
|
|
|
|
const month = date.getMonth()
|
|
|
|
|
@@ -353,7 +373,7 @@ async function readFirstExistingJson(paths) {
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (error.code !== 'ENOENT') {
|
|
|
|
|
console.error(`Fehler beim Lesen der Spielplan-JSON ${filePath}:`, error)
|
|
|
|
|
logReadError('Fehler beim Lesen der Spielplan-JSON', filePath, error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -374,7 +394,7 @@ async function readFirstExistingCsv(paths) {
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (error.code !== 'ENOENT') {
|
|
|
|
|
console.error(`Fehler beim Lesen der Spielplan-CSV ${filePath}:`, error)
|
|
|
|
|
logReadError('Fehler beim Lesen der Spielplan-CSV', filePath, error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -419,7 +439,7 @@ export async function listSpielplanSeasons() {
|
|
|
|
|
entries = await fs.readdir(directory)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (error.code !== 'ENOENT') {
|
|
|
|
|
console.error(`Fehler beim Lesen des Spielplan-Saisonverzeichnisses ${directory}:`, error)
|
|
|
|
|
logReadError('Fehler beim Lesen des Spielplan-Saisonverzeichnisses', directory, error)
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
@@ -468,5 +488,7 @@ export async function readSpielplanData(options = {}) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getSpielplanSeasonJsonPathForCsvPath(csvPath, seasonSlug) {
|
|
|
|
|
return path.join(path.dirname(csvPath), 'spielplaene', `spielplan-${seasonSlug}.json`)
|
|
|
|
|
const safeCsvPath = normalizeSpielplanCsvPath(csvPath)
|
|
|
|
|
const safeSeasonSlug = requireSeasonSlug(seasonSlug)
|
|
|
|
|
return `${path.dirname(safeCsvPath)}/spielplaene/spielplan-${safeSeasonSlug}.json`
|
|
|
|
|
}
|
|
|
|
|
|