feat(setup): USB printer discovery — pick a real /dev/usb device
The kernel numbers usblp nodes by plug/boot order (park-buzi's printer
is lp1); the wizard hardcoded lp0 in labels/default and the admin had to
shell in and `ls /dev/usb`. Now:
- GET /api/setup/usb-printers enumerates /dev/usb/lpN (visible via the
compose bind-mount) and enriches each with the printer's self-reported
make/model from sysfs ieee1284_id (readable through Docker's ro /sys).
- The wizard's devicePath becomes a SELECT of printers actually present
("/dev/usb/lp1 — Xprinter XP-K200L"): a fresh form preselects the
first real device; a saved-but-unplugged path stays selectable,
flagged "saved — not present now"; zero found falls back to free text
+ a check-the-cable hint.
- Transport option label no longer hardcodes lp0.
Wiki: printer-usb-transport marked HARDWARE-VERIFIED (lab 2026-07-07:
full slip + feed + cut over USB — parity with TCP).
Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
This commit is contained in:
@@ -560,6 +560,39 @@ export async function setupRoutes(
|
||||
},
|
||||
);
|
||||
|
||||
// USB printers PRESENT on the box: enumerate /dev/usb/lpN (the usblp nodes the
|
||||
// container sees via the /dev/usb bind-mount) and enrich each with the printer's
|
||||
// self-reported make/model from sysfs (ieee1284_id — readable through Docker's
|
||||
// default ro /sys). The wizard offers these as a SELECT so the admin never has to
|
||||
// shell in and `ls /dev/usb` to learn the kernel picked lp1 (field friction,
|
||||
// park-buzi 2026-07-07). Empty list = no usblp printer plugged/visible.
|
||||
app.get("/api/setup/usb-printers", { preHandler: adminGuard }, async () => {
|
||||
const { readdir, readFile } = await import("node:fs/promises");
|
||||
let names: string[] = [];
|
||||
try {
|
||||
names = (await readdir("/dev/usb")).filter((n) => /^lp\d+$/.test(n)).sort();
|
||||
} catch {
|
||||
return { printers: [] }; // no /dev/usb at all — nothing plugged (or no mount)
|
||||
}
|
||||
const printers = await Promise.all(
|
||||
names.map(async (n) => {
|
||||
// ieee1284_id: "MFG:Xprinter;CMD:ESCPOS;MDL:XP-K200L;…" — best-effort.
|
||||
let description: string | null = null;
|
||||
try {
|
||||
const id = await readFile(`/sys/class/usbmisc/${n}/device/ieee1284_id`, "utf8");
|
||||
const pick = (key: string) => id.match(new RegExp(`(?:^|;)\\s*${key}:([^;]+)`, "i"))?.[1]?.trim();
|
||||
const mfg = pick("MFG") ?? pick("MANUFACTURER");
|
||||
const mdl = pick("MDL") ?? pick("MODEL");
|
||||
description = [mfg, mdl].filter(Boolean).join(" ") || null;
|
||||
} catch {
|
||||
/* sysfs not readable / attribute absent — path alone is still useful */
|
||||
}
|
||||
return { path: `/dev/usb/${n}`, description };
|
||||
}),
|
||||
);
|
||||
return { printers };
|
||||
});
|
||||
|
||||
// Assign a device. Validates the chosen driver + config, configures the device
|
||||
// (fix preconditions + set up Digest-authenticated input push — no manual device-
|
||||
// web-UI step by the admin), then persists. Fails the save if the device can't be
|
||||
|
||||
Reference in New Issue
Block a user