chore: update version to 1.8.13 and dependencies; enhance CSV sorting for championships
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 6m56s
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-10-22 23:03:26 +02:00
parent 5c964592a8
commit b86555744f
5 changed files with 2706 additions and 2405 deletions

View File

@@ -10,6 +10,74 @@ async function exists(filePath) {
}
}
function parseCsvLine(line) {
const values = []
let value = ''
let quoted = false
for (let index = 0; index < line.length; index++) {
const char = line[index]
if (char === '"') {
if (quoted && line[index + 1] === '"') {
value += '"'
index++
} else {
quoted = !quoted
}
} else if (char === ',' && !quoted) {
values.push(value.trim())
value = ''
} else {
value += char
}
}
values.push(value.trim())
return values
}
function categoryOrder(category) {
const normalized = category.toLocaleLowerCase('de-DE')
if (normalized.includes('einzel')) return 0
if (normalized.includes('doppel')) return 1
return 2
}
function placementOrder(placement) {
const match = String(placement).match(/\d+/)
return match ? Number(match[0]) : Number.MAX_SAFE_INTEGER
}
function sortChampionshipCsv(csv) {
const newline = csv.includes('\r\n') ? '\r\n' : '\n'
const lines = csv.split(/\r?\n/)
const [header, ...dataLines] = lines
const entries = dataLines
.filter(line => line.trim() !== '')
.map((line, index) => ({ line, values: parseCsvLine(line), index }))
entries.sort((a, b) => {
const yearA = Number(a.values[0])
const yearB = Number(b.values[0])
if (Number.isFinite(yearA) && Number.isFinite(yearB) && yearA !== yearB) return yearB - yearA
const categoryA = a.values[1] || ''
const categoryB = b.values[1] || ''
const categoryDifference = categoryOrder(categoryA) - categoryOrder(categoryB)
if (categoryDifference !== 0) return categoryDifference
const categoryNameDifference = categoryA.localeCompare(categoryB, 'de-DE')
if (categoryNameDifference !== 0) return categoryNameDifference
const placementDifference = placementOrder(a.values[2]) - placementOrder(b.values[2])
if (placementDifference !== 0) return placementDifference
return a.index - b.index
})
return [header, ...entries.map(entry => entry.line)].join(newline)
}
export default defineEventHandler(async (event) => {
try {
const cwd = process.cwd()
@@ -50,7 +118,7 @@ export default defineEventHandler(async (event) => {
setHeader(event, 'Pragma', 'no-cache')
setHeader(event, 'Expires', '0')
return csv
return sortChampionshipCsv(csv)
} catch (error) {
if (error?.statusCode) throw error
console.error('Fehler beim Laden der Vereinsmeisterschaften:', error)
@@ -60,4 +128,3 @@ export default defineEventHandler(async (event) => {
})
}
})