Printer Adjustments

This commit is contained in:
2026-09-07 10:56:01 +10:00
parent 511929d579
commit 28b52145eb
6 changed files with 85 additions and 12 deletions
+5
View File
@@ -27,6 +27,7 @@ CREATE TABLE IF NOT EXISTS sites (
printer_port INTEGER NOT NULL DEFAULT 9100,
printer_model TEXT NOT NULL DEFAULT 'QL-820NWB',
printer_rotate INTEGER NOT NULL DEFAULT 0,
printer_label TEXT NOT NULL DEFAULT '62',
banner_path TEXT,
banner_height INTEGER NOT NULL DEFAULT 64,
banner_align TEXT NOT NULL DEFAULT 'left',
@@ -183,6 +184,10 @@ addColumn('sites', 'printer_host', 'TEXT');
addColumn('sites', 'printer_port', 'INTEGER NOT NULL DEFAULT 9100');
addColumn('sites', 'printer_model', "TEXT NOT NULL DEFAULT 'QL-820NWB'");
addColumn('sites', 'printer_rotate', 'INTEGER NOT NULL DEFAULT 0');
// Which roll is physically loaded. Kept separate from the red styling option:
// the printer refuses a two-colour job on a plain roll, so guessing the media
// from a design setting means a wrong-roll error nobody can explain.
addColumn('sites', 'printer_label', "TEXT NOT NULL DEFAULT '62'");
addColumn('frequent_visitors', 'company', 'TEXT');
db.exec('CREATE INDEX IF NOT EXISTS idx_visits_site ON visits(site_id, signed_out_at)');
+24 -3
View File
@@ -41,9 +41,26 @@ export function isConfigured(site) {
return Boolean(site?.printer_enabled && site?.printer_host);
}
/** brother_ql's label id. The two-colour roll is a different label to the plain one. */
/**
* brother_ql's media id for the roll that is actually loaded.
*
* This is set explicitly rather than inferred from the red styling option. A
* two-colour job sent to a plain roll is rejected by the printer with "Wrong
* Roll Type", which gives no clue that a colour checkbox caused it.
*/
export const ROLL_TYPES = {
'62': '62 mm continuous, black only',
'62red': '62 mm continuous, black and red (DK-22251)',
};
export function labelFor(site) {
return site?.badge_accent ? '62red' : '62';
const label = site?.printer_label;
return Object.hasOwn(ROLL_TYPES, label) ? label : '62';
}
/** Red ink only exists on the two-colour roll; anywhere else it prints dark grey. */
export function accentWillPrintRed(site) {
return Boolean(site?.badge_accent) && labelFor(site) === '62red';
}
/* ------------------------------------------------------------ rendering */
@@ -223,7 +240,8 @@ export async function renderBadgePng(visit, site) {
const design = createCanvas(designW, designH);
const ctx = design.getContext('2d');
const accent = Boolean(site.badge_accent);
// Only paint red when the loaded roll can actually print it.
const accent = accentWillPrintRed(site);
// Measure first, then draw the block centred down the label. Without this the
// content hugs the top and leaves a wide blank strip at the bottom of every badge.
@@ -273,6 +291,9 @@ function explainPrintError(output, host) {
if (/Unknown label|label/i.test(last) && /identifier/i.test(last)) {
return 'The printer rejected the label size. Check the roll loaded matches the badge settings.';
}
if (/wrong roll|WrongMedia|media/i.test(last)) {
return 'The printer says the roll is wrong. Check "Roll loaded in the printer" matches what is actually in the machine — a black and red job is refused on a plain roll.';
}
return last || 'The printer did not accept the job.';
}
+5 -2
View File
@@ -397,7 +397,7 @@ router.patch('/sites/:id', (req, res) => {
badge_height_mm = ?, badge_show_photo = ?, badge_accent = ?, badge_note = ?,
colour_brand = ?, colour_signout = ?, colour_page = ?, colour_text = ?,
banner_height = ?, banner_align = ?, printer_enabled = ?, printer_host = ?,
printer_port = ?, printer_model = ?, printer_rotate = ? WHERE id = ?`
printer_port = ?, printer_model = ?, printer_rotate = ?, printer_label = ? WHERE id = ?`
).run(
clean(req.body?.name ?? site.name, 100) || site.name,
req.body?.slug ? uniqueSlug(req.body.slug, site.id) : site.slug,
@@ -432,7 +432,10 @@ router.patch('/sites/:id', (req, res) => {
printerCfg.model !== undefined ? clean(printerCfg.model, 40) || 'QL-820NWB' : site.printer_model,
printerCfg.rotate !== undefined
? ([0, 90, 180, 270].includes(Number(printerCfg.rotate)) ? Number(printerCfg.rotate) : 0)
: site.printer_rotate
: site.printer_rotate,
printerCfg.label !== undefined
? (Object.hasOwn(printer.ROLL_TYPES, printerCfg.label) ? printerCfg.label : '62')
: site.printer_label
, site.id);
res.json(shapeSite(db.prepare('SELECT * FROM sites WHERE id = ?').get(site.id)));
+1
View File
@@ -65,6 +65,7 @@ export function shapeSite(site) {
port: site.printer_port || 9100,
model: site.printer_model || 'QL-820NWB',
rotate: site.printer_rotate || 0,
label: site.printer_label || '62',
},
badge: {
enabled: Boolean(site.badge_enabled),