Printing Debug

This commit is contained in:
2026-09-07 11:18:13 +10:00
parent 8bc71792e3
commit eb986581e4
5 changed files with 123 additions and 25 deletions
+31 -1
View File
@@ -510,10 +510,40 @@ router.post('/sites/:id/test-print', async (req, res) => {
const result = await printer.printBadge(printer.sampleVisit(site), site);
res.json({ ok: true, ...result });
} catch (err) {
res.status(400).json({ error: err.message });
// The raw output and the exact command matter when the friendly message is
// not enough — a printer refusing a job says why in its own words.
res.status(400).json({ error: err.message, raw: err.raw || null, command: err.command || null });
}
});
/** Everything about how this site would print, for working out why it will not. */
router.get('/sites/:id/printer-diagnostics', (req, res) => {
const site = db.prepare('SELECT * FROM sites WHERE id = ?').get(req.params.id);
if (!site) return res.status(404).json({ error: 'Not found.' });
res.json({
site: site.name,
printing: {
enabled: Boolean(site.printer_enabled),
host: site.printer_host,
port: site.printer_port,
model: site.printer_model,
rotate: site.printer_rotate,
},
rollSetting: site.printer_label,
labelSentToPrinter: printer.labelFor(site),
redRequested: Boolean(site.badge_accent),
redWillPrint: printer.accentWillPrintRed(site),
badgeMm: { width: site.badge_width_mm, height: site.badge_height_mm },
lastResult: printer.printerStatus(site.id),
command: [
'brother_ql --backend network',
`--model ${site.printer_model || 'QL-820NWB'}`,
`--printer tcp://${site.printer_host}:${site.printer_port || 9100}`,
`print --label ${printer.labelFor(site)} badge.png`,
].join(' '),
});
});
/** Reprints a real visitor's badge on the server's printer. */
router.post('/visits/:id/print', async (req, res) => {
const visit = db.prepare('SELECT * FROM visits WHERE id = ?').get(req.params.id);