Files
harheimertc/server/api/spielplaene.get.js
Torsten Schulz (local) 3586704cce
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 10m29s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Has been skipped
Update file permissions for multiple server and test files to executable mode
2026-07-15 08:45:12 +02:00

32 lines
825 B
JavaScript
Executable File

import { promises as fs } from 'fs'
import path from 'path'
export default defineEventHandler(async (event) => {
try {
const spielplaeneDir = path.join(process.cwd(), 'public', 'spielplaene')
// Prüfe, ob das Verzeichnis existiert
try {
await fs.access(spielplaeneDir)
} catch {
return []
}
// Lese alle Dateien im Verzeichnis
const dateien = await fs.readdir(spielplaeneDir)
// Filtere nur relevante Dateitypen
const erlaubteExtensions = ['.pdf', '.xlsx', '.xls', '.doc', '.docx']
const gefiltert = dateien.filter(datei => {
const ext = path.extname(datei).toLowerCase()
return erlaubteExtensions.includes(ext)
})
return gefiltert
} catch (error) {
console.error('Fehler beim Lesen der Spielpläne:', error)
return []
}
})