feat: use canonical diensten root

This commit is contained in:
Eddy de Vink 2026-08-17 19:59:17 +02:00
commit bd8b5a5a66
3 changed files with 32 additions and 12 deletions

View file

@ -3,11 +3,31 @@ const path = require('path')
let dienstenCache = null
function getDienstenDir() {
if (!process.env.DIENSTEN_DIR) {
throw new Error('DIENSTEN_DIR is required; configure the canonical Whatsapp_Dienst/diensten directory')
}
return path.resolve(process.env.DIENSTEN_DIR)
}
function loadDiensten() {
if (dienstenCache) return dienstenCache
const jsonPath = process.env.DIENSTEN_JSON
const raw = fs.readFileSync(jsonPath, 'utf-8')
dienstenCache = JSON.parse(raw)
const dienstenDir = getDienstenDir()
const jsonPath = path.join(dienstenDir, 'dienst-tijden.json')
let raw
try {
raw = fs.readFileSync(jsonPath, 'utf-8')
} catch (err) {
throw new Error(`Failed to read canonical diensten JSON at ${jsonPath}: ${err.message}`)
}
try {
dienstenCache = JSON.parse(raw)
} catch (err) {
throw new Error(`Failed to parse canonical diensten JSON at ${jsonPath}: ${err.message}`)
}
return dienstenCache
}
@ -17,7 +37,7 @@ function findDienst(dienstnummer) {
}
function getPngFilePaths(dienst) {
const pngDir = process.env.DIENSTEN_PNG
const pngDir = path.join(getDienstenDir(), 'png')
return dienst.paginas.map(p => path.join(pngDir, p.bestandsnaam))
}