CertZipDL

This commit is contained in:
2026-09-16 10:05:57 +10:00
parent b1a793302d
commit 922ce99d25
13 changed files with 577 additions and 63 deletions
+100
View File
@@ -0,0 +1,100 @@
/**
* Tries roll ids one at a time, waiting for you to say what came out.
*
* docker compose exec -it visitor-signin node scripts/print-probe.mjs
*
* Note the -it: this asks questions, so the container needs a terminal attached.
*
* Start with printer-status.mjs — if the printer answers, it tells you the right
* id outright and this is unnecessary. Use this when the printer will not report
* its status, or when it does and the job is still refused.
*/
import fs from 'node:fs';
import readline from 'node:readline/promises';
import { execFileSync } from 'node:child_process';
import db from '../src/db.js';
import config from '../src/config.js';
import * as printer from '../src/printer.js';
// Ordered by how likely each is on a 62 mm machine, cheapest guesses first.
const CANDIDATES = [
['62', '62 mm continuous, black only'],
['62x100', '62 x 100 mm die-cut'],
['62red', '62 mm continuous, black and red (DK-22251)'],
['62x29', '62 x 29 mm die-cut'],
['29', '29 mm continuous'],
['29x90', '29 x 90 mm die-cut'],
['38', '38 mm continuous'],
['50', '50 mm continuous'],
['54', '54 mm continuous'],
];
const site = db
.prepare('SELECT * FROM sites WHERE printer_host IS NOT NULL ORDER BY id LIMIT 1')
.get();
if (!site) {
console.error('No site has a printer address set.');
process.exit(1);
}
const target = `tcp://${site.printer_host}:${site.printer_port || 9100}`;
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
console.log(`\n Printer: ${site.printer_model || 'QL-820NWB'} at ${target}`);
console.log(' One label will be sent per attempt. After each, say whether anything came out.');
console.log(' Press Ctrl+C at any point to stop.\n');
const results = [];
for (const [label, description] of CANDIDATES) {
const answer = (await rl.question(` Try "${label}" (${description})? [Y/n/q] `)).trim().toLowerCase();
if (answer === 'q') break;
if (answer === 'n') {
results.push([label, 'skipped']);
continue;
}
const png = await printer.renderBadgePng(printer.sampleVisit(site), { ...site, printer_label: label });
const file = '/tmp/probe.png';
fs.writeFileSync(file, png);
let sent = true;
let detail = '';
try {
execFileSync(
config.printing.command,
[
'--backend', 'network',
'--model', site.printer_model || 'QL-820NWB',
'--printer', target,
'print', '--label', label, file,
],
{ stdio: ['ignore', 'pipe', 'pipe'], timeout: config.printing.timeoutMs }
);
} catch (err) {
sent = false;
detail = `${err.stdout || ''}${err.stderr || ''}`.trim().split('\n').pop() || err.message;
}
if (!sent) {
console.log(` could not send: ${detail}\n`);
results.push([label, `send failed: ${detail}`]);
continue;
}
const came = (await rl.question(' Did a label print? [y/N] ')).trim().toLowerCase();
if (came === 'y') {
results.push([label, 'PRINTED']);
console.log(`\n That is the one. Set "Roll loaded in the printer" so it sends ${label}.\n`);
break;
}
results.push([label, 'nothing came out']);
console.log(' Clear the error on the printer (open and close the cover) before the next try.\n');
}
rl.close();
console.log(' Summary');
for (const [label, outcome] of results) console.log(` ${label.padEnd(8)} ${outcome}`);
console.log('');