feat: use canonical diensten root
This commit is contained in:
parent
b3178ef3f2
commit
bd8b5a5a66
3 changed files with 32 additions and 12 deletions
|
|
@ -16,8 +16,7 @@ ALLOWED_GROUP=120363407613652082@g.us
|
|||
BOT_NAME=EdGpt
|
||||
|
||||
# Paths
|
||||
DIENSTEN_JSON=./diensten/dienst-tijden.json
|
||||
DIENSTEN_PNG=./diensten/png
|
||||
DIENSTEN_DIR=../Whatsapp_Dienst/diensten
|
||||
|
||||
# Rate limiting
|
||||
MAX_REQUESTS_PER_DAY=5
|
||||
|
|
|
|||
13
README.md
13
README.md
|
|
@ -41,9 +41,8 @@ WHATSAPP_SESSION=EdGpt
|
|||
WEBHOOK_PORT=3002
|
||||
ALLOWED_GROUP=120363407613652082@g.us
|
||||
|
||||
# Bestanden
|
||||
DIENSTEN_JSON=./diensten/dienst-tijden.json
|
||||
DIENSTEN_PNG=./diensten/png
|
||||
# Canonical dienstenroot (alleen-lezen consumer)
|
||||
DIENSTEN_DIR=../Whatsapp_Dienst/diensten
|
||||
|
||||
# Admin
|
||||
ADMIN_NUMBER=31620248011@c.us
|
||||
|
|
@ -68,7 +67,9 @@ Belangrijk: gebruik **`docker compose up -d`** (niet `docker restart`) om `.env`
|
|||
|
||||
## Data
|
||||
|
||||
De map `diensten/` bevat:
|
||||
`Whatsapp_Dienst` is de enige eigenaar van bron-PDF's en gegenereerde dienstenartefacten. De echo-bot heeft geen eigen actieve `diensten/`-directory en leest uitsluitend de root die met `DIENSTEN_DIR` is geconfigureerd.
|
||||
|
||||
Onder `DIENSTEN_DIR` staan:
|
||||
|
||||
- `dienst-tijden.json` — array met dienstmetadata:
|
||||
```json
|
||||
|
|
@ -84,9 +85,9 @@ De map `diensten/` bevat:
|
|||
}
|
||||
]
|
||||
```
|
||||
- `png/` — PNG bestanden met dienstschema's (bijv. `4002-001.png`)
|
||||
- `png/` — PNG-bestanden met dienstschema's (bijv. `4002-001.png`)
|
||||
|
||||
Beide zijn uitgesloten van git via `.gitignore`.
|
||||
`DIENSTEN_DIR` is de enige data-padvariabele. De echo-bot maakt of genereert geen bestanden in deze root.
|
||||
|
||||
## Gebruik
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue