Public Access
Printing Debug
This commit is contained in:
+31
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user