Printing Debug

This commit is contained in:
jessikitty committed 2026-09-07 11:18:13 +10:00
1 parent 8bc71792e3
commit eb986581e4
5 files changed
+123 -25

No files matched your search

+14 -12
View File
@@ -336,24 +336,26 @@ export async function printBadge(visit, site) {
const port = Number(site.printer_port) || 9100;
const target = `tcp://${site.printer_host}:${port}`;
const args = [
'--backend', 'network',
'--model', site.printer_model || 'QL-820NWB',
'--printer', target,
'print',
'--label', labelFor(site),
file,
];
try {
await runBrotherQl(
[
'--backend', 'network',
'--model', site.printer_model || 'QL-820NWB',
'--printer', target,
'print',
'--label', labelFor(site),
file,
],
config.printing.timeoutMs
);
await runBrotherQl(args, config.printing.timeoutMs);
note(site.id, true, `Printed to ${site.printer_host}`);
return { ok: true, target };
} catch (err) {
const friendly = explainPrintError(err.message, site.printer_host);
note(site.id, false, friendly);
throw new Error(friendly);
const wrapped = new Error(friendly);
wrapped.raw = err.message;
wrapped.command = `${config.printing.command} ${args.join(' ')}`;
throw wrapped;
} finally {
fs.rm(file, { force: true }, () => {});
}
+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);