Add the notify and ntfy modules and scoped tokens
Security / Vulnerability check (push) Successful in 41s
Test / Lint and test (push) Successful in 1m57s

Breaking: a job with a raw element prints only with a token issued with
uberbringer token --raw. Every other token, every existing one included,
gets 403 token_scope for it, with the raw elements in details, and keeps
every other route.

The notify module prints a notification card from a title, message,
priority and tags, with topic, click, up to three actions, image,
markdown and time as options; it decodes strictly and refuses a payload
over its length caps. The ntfy module takes one ntfy message as ntfy
sends it, such as the ntfy client's $NTFY_RAW, ignores fields it does
not know, cuts text over the caps, and answers 204 for other events and
binary bodies. Both print every message plain: one message cannot tell
the first of a sequence from a replacement, since a publisher may choose
the sequence ID. internal/pkg/ntfy holds ntfy's message types.

Both print the same card. The priority picks the form: a dark URGENT
rule and a double box, a double box headed HIGH, a single box with the
title in its border, or a rule with no box. Tags print as markers in
front of the title, the rest on a Tags row; links print as QR codes with
their labels; attached PNG, JPEG, GIF and WebP images print after the
card. A line-level markdown subset is laid out without a dependency,
keeping marks inside code spans and URLs, and emoji are removed after a
few typed ones become markers. A card that cannot be laid out prints as
a plain receipt, and the server logs the fault once at ERROR and reports
it to Sentry once. [ntfy.format] and [ntfy.markers] shape the cards; the
markers table is a setting with the user's own keys, also settable as
UBERBRINGER_NTFY_MARKERS=name=value,...

uberbringer token --modules issues a token limited to those modules'
print and preview routes, job status and the module list; each route in
the table says which tokens it takes, and a scope claim that could read
as absent makes the token invalid. image elements take optional, which
also shrinks a too-wide image to the paper; a QR code that could be too
wide for the paper prints with smaller modules; box takes title_bold.
Submit takes a Meta whose source shows in job status and, with a copy
of the request ID, in every worker log line of the job.

The four ntfy cards passed on the TM-T88IV, posted as the client recipe
posts them, and their bytes are pinned in TestPaperReceipts. docs/api.md
describes the modules, the card and the client recipe, with tokens read
from a header file; docs/swagger.json is regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-30 13:57:08 -06:00
1 parent fa15cb27b1
commit 1335ed0687
119 files changed
+5626 -468

No files matched your search

+12 -7
View File
@@ -53,7 +53,7 @@ func (r *Renderer) Preview(ctx context.Context, job Job) (Preview, error) {
if err != nil {
return Preview{}, fmt.Errorf("reading back the rendered receipt: %w", err)
}
labelImages(lines, job)
labelImages(lines, job, r.options.Profile.DotsPerLine)
var warnings []string
for i := range job.Elements {
@@ -79,7 +79,8 @@ func (r *Renderer) Preview(ctx context.Context, job Job) (Preview, error) {
// placeholderImages returns a blank one-row raster across the paper for
// every image element, and a warning for each image that would fail to
// print because it is wider than the paper.
// print because it is wider than the paper. An optional image that is
// wider shrinks to the paper instead.
func (r *Renderer) placeholderImages(job Job) (map[int]*image.Paletted, map[int]string) {
paper := r.options.Profile.DotsPerLine
images := make(map[int]*image.Paletted)
@@ -88,7 +89,7 @@ func (r *Renderer) placeholderImages(job Job) (map[int]*image.Paletted, map[int]
if el.Type != TypeImage {
continue
}
if el.Width > paper {
if el.Width > paper && !el.Optional {
warnings[i] = fmt.Sprintf("elements[%d] (image): width %d is wider than the %d-dot paper, so the job would fail", i, el.Width, paper)
}
images[i] = image.NewPaletted(image.Rect(0, 0, paper, 1), color.Palette{color.White, color.Black})
@@ -97,8 +98,9 @@ func (r *Renderer) placeholderImages(job Job) (map[int]*image.Paletted, map[int]
}
// labelImages replaces the size of each image placeholder with the source
// of its element, in order, copy after copy.
func labelImages(lines []escpos.PreviewLine, job Job) {
// of its element, in order, copy after copy. An optional image wider than
// the paper, paper dots, is labelled with the width it prints at.
func labelImages(lines []escpos.PreviewLine, job Job, paper int) {
var sources []Element
for _, el := range job.Elements {
if el.Type == TypeImage {
@@ -117,8 +119,11 @@ func labelImages(lines []escpos.PreviewLine, job Job) {
name, data = imageName(el.URL), el.URL
}
lines[i].Text = fmt.Sprintf("[image: %s]", name)
if el.Width > 0 {
lines[i].Text = fmt.Sprintf("[image %d dots: %s]", el.Width, name)
if width := el.Width; width > 0 {
if el.Optional {
width = min(width, paper)
}
lines[i].Text = fmt.Sprintf("[image %d dots: %s]", width, name)
}
lines[i].Data = data
}