Files
harheimertc/server/api/galerie.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

42 lines
1.1 KiB
JavaScript
Executable File

import { promises as fs } from 'fs'
import path from 'path'
export default defineEventHandler(async (event) => {
try {
const galerieDir = path.join(process.cwd(), 'public', 'galerie')
// Prüfe, ob das Verzeichnis existiert
try {
await fs.access(galerieDir)
} catch {
return []
}
// Lese alle Dateien im Verzeichnis
const dateien = await fs.readdir(galerieDir)
// Filtere nur Bilddateien
const erlaubteExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg']
const bilder = dateien.filter(datei => {
const ext = path.extname(datei).toLowerCase()
return erlaubteExtensions.includes(ext)
})
// Erstelle Bildobjekte mit Titel basierend auf Dateiname
return bilder.map(filename => {
const nameWithoutExt = path.parse(filename).name
const title = nameWithoutExt
.replace(/[-_]/g, ' ')
.replace(/\b\w/g, l => l.toUpperCase())
return {
filename,
title
}
})
} catch (error) {
console.error('Fehler beim Lesen der Galerie:', error)
return []
}
})