membership: refactor form filling, add smoke tests and debug-guard fallback; fix mappings

This commit is contained in:
Torsten Schulz (local)
2025-10-23 14:21:05 +02:00
parent f14597006e
commit e029154a8c
9 changed files with 662 additions and 295 deletions

View File

@@ -0,0 +1,40 @@
import fs from 'fs'
import path from 'path'
import { PDFDocument } from 'pdf-lib'
async function main() {
const uploads = path.join(process.cwd(), 'public', 'uploads')
const files = fs.existsSync(uploads) ? fs.readdirSync(uploads).filter(f => f.toLowerCase().endsWith('.pdf')) : []
if (files.length === 0) { console.log('no pdfs'); return }
files.sort((a,b) => fs.statSync(path.join(uploads,b)).mtimeMs - fs.statSync(path.join(uploads,a)).mtimeMs)
const latest = path.join(uploads, files[0])
console.log('Inspecting', latest)
const bytes = fs.readFileSync(latest)
const pdf = await PDFDocument.load(bytes)
let form
try { form = pdf.getForm() } catch (e) { form = null }
if (!form) { console.log('no form'); return }
const fields = form.getFields()
const matches = []
for (const f of fields) {
const name = f.getName()
try {
if (typeof f.getText === 'function') {
const v = f.getText()
if (v && (String(v).toLowerCase() === 'aktiv' || String(v).toLowerCase() === 'passiv')) {
matches.push({ name, value: v })
}
} else if (typeof f.isChecked === 'function') {
const checked = f.isChecked()
if (checked) {
// value true -> possibly membership
matches.push({ name, value: 'checked' })
}
}
} catch (e) {}
}
if (matches.length === 0) console.log('no aktiv/passiv values found')
else console.log('matches:', matches)
}
main().catch(e => { console.error(e); process.exit(1) })