Render every print to a complete ESC/POS payload (reset, content, cut)
and send it once over a fresh connection. Only the connect is retried,
so a link that drops mid-job can no longer print a partial image followed
by a full one, and no text size leaks into the next job. Prints are
capped at about 1 m of paper: tall images shrink, over-long notes are
refused.
Replace the argparse/stdout plumbing with PrinterConfig, InvalidJob and
PrinterUnavailable, and one run_command() dispatcher shared by the CLI
and TUI. Status now really connects; before, escpos's lazy open meant
the web server always reported the printer ready. Rendering with the
TM-T20II profile makes QR centering take effect.
The web server validates and renders jobs in the request (400 on bad
input), queues them for a single worker and answers 202; the page
long-polls /api/jobs/{id}, so no request outlives nginx's proxy timeout
while its job still prints. Status reports busy instead of waiting, and
jobs are logged with the nginx user.
update.sh tests new commits in a scratch worktree before touching the
live clone, and rolls back if /healthz doesn't answer after the restart.
The unit runs from the venv, and the web server defaults to localhost.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
25 lines
955 B
Desktop File
25 lines
955 B
Desktop File
# Web server for printing from the site (see README "Printing from the website").
|
|
#
|
|
# Install as a user unit on the machine the printer is cabled to:
|
|
# cp deploy/receipt-web.service ~/.config/systemd/user/
|
|
# systemctl --user daemon-reload && systemctl --user enable --now receipt-web
|
|
# sudo loginctl enable-linger "$USER" # start at boot, without logging in
|
|
#
|
|
# ~/.config/receipt-web.env holds RECEIPT_WEB_TOKEN=<secret> (chmod 600); the
|
|
# site's nginx sends the same value. RECEIPT_WEB_LISTEN overrides the default
|
|
# bind address (this machine's Tailscale IP).
|
|
[Unit]
|
|
Description=Receipt printer web server
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
EnvironmentFile=%h/.config/receipt-web.env
|
|
ExecStart=%h/Coding/receipt_maker/.venv/bin/python %h/Coding/receipt_maker/receipt.py serve
|
|
# Binding fails until Tailscale has brought its address up; just retry.
|
|
Restart=always
|
|
RestartSec=5
|
|
|
|
[Install]
|
|
WantedBy=default.target
|