Add the notify and ntfy modules and scoped tokens
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:
1 parent
fa15cb27b1
commit
1335ed0687
119 files changed
+5626
-468
No files matched your search
+28
-320
@@ -1,6 +1,6 @@
|
||||
# Plan: CP437 blocks, modules and ntfy printing
|
||||
|
||||
Status: **phases 1 and 2 are done**. Phase 1: box, rule and kv, text folding and the preview. Phase 2: the list block, the module layer, the note module and its routes, and `[format] timezone` and `time_layout`. Both are built and checked on paper (docs/api.md § Blocks and § Modules, design.md). Phases 3-5 are not started. Every design decision for phases 3-4 is made; the open questions left are an assumed default, config values and the second printer. Each phase runs in its own session, briefed from its section.
|
||||
Status: **phases 1-3 are done**. Phase 1: box, rule and kv, text folding and the preview. Phase 2: the list block, the module layer, the note module and its routes, and `[format] timezone` and `time_layout`. Phase 3: the notify and ntfy modules and their cards, scoped tokens, optional images and job sources. All three are built and checked on paper (docs/api.md § Blocks and § Modules, design.md). Phases 4-5 are not started. Every design decision for phase 4 is made; the open questions left are config values and the second printer. Each phase runs in its own session, briefed from its section.
|
||||
|
||||
## Decisions (owner, 2026-11-29)
|
||||
|
||||
@@ -42,10 +42,10 @@ Ideas taken from the other designs:
|
||||
- From Design 2 (templates): fit boxes, a hand-written markdown subset with no new dependency, a plain fallback receipt, a since=<time> cursor, token scopes, and '?' warnings in preview.
|
||||
- From Design 3 (sources): a simple Notice input (the notify module), images marked optional, a cursor taken from ntfy server time, the time/tzdata import, and Submit Meta for traceability.
|
||||
|
||||
WHAT SHIPS WHEN (about 8 developer days left to the end of phase 4)
|
||||
WHAT SHIPS WHEN (about 5 developer days left to the end of phase 4)
|
||||
1. Boxes and preview: done.
|
||||
2. Notes and modules: done. POST /api/v1/print/note {title, text, items} prints a boxed checklist.
|
||||
3. Notifications, 3 days. POST /api/v1/print/notify {title, message, priority, tags} is for scripts and phone shortcuts. POST /api/v1/print/ntfy takes the ntfy CLI's $NTFY_RAW unchanged. After this phase, ntfy printing needs only a client.yml entry and no jq.
|
||||
3. Notifications: done. POST /api/v1/print/notify {title, message, priority, tags} is for scripts and phone shortcuts. POST /api/v1/print/ntfy takes the ntfy CLI's $NTFY_RAW unchanged, so ntfy printing needs only a client.yml entry and no jq.
|
||||
4. Built-in ntfy subscriber, 5 days. You only change the config. It reconnects safely, removes duplicates, caps the backlog, folds floods into a digest receipt, and holds non-urgent messages during quiet hours for a morning digest.
|
||||
5. Later, on demand: the second-printer pool, user templates, an ntfy-compatible publish endpoint, table/banner/spans, and webhooks.
|
||||
|
||||
@@ -58,28 +58,26 @@ WHERE THE JUDGES DISAGREED, AND WHAT THIS PLAN CHOSE
|
||||
- list: in (phase 2), because the note module needs checklists.
|
||||
- spans, table, group, banner, nested boxes and goldmark: deferred.
|
||||
- Geometry checks in the HTTP handler (Renderer.Check): rejected. Layout never fails on a valid job, preview shows the result and line count synchronously, and each module caps its own length.
|
||||
- Scoped tokens: in phase 3, before any integration token is handed out.
|
||||
- Scoped tokens: built in phase 3; design.md records the decision.
|
||||
- Quiet hours: phase 4, as a morning digest (owner decision).
|
||||
|
||||
## Open questions
|
||||
|
||||
Before phase 3 (assumed unless the owner says otherwise):
|
||||
|
||||
1. Integration tokens: tokens created with --modules can only use module
|
||||
routes, while existing tokens keep full access including raw ESC/POS.
|
||||
|
||||
Before phase 4 (config, not design):
|
||||
|
||||
2. Topics and auth: which topics and quiet-hours window to configure. A
|
||||
1. Topics and auth: which topics and quiet-hours window to configure. A
|
||||
dedicated read-only ntfy user with an access token is assumed.
|
||||
|
||||
When the second printer arrives:
|
||||
|
||||
3. Which jobs and ntfy topics go to which printer, and should urgent messages
|
||||
2. Which jobs and ntfy topics go to which printer, and should urgent messages
|
||||
print on both?
|
||||
|
||||
## Mockups (42 columns, CP437)
|
||||
|
||||
The notification cards are built: docs/api.md § Notification cards shows
|
||||
the four priority forms as they printed. Still to come:
|
||||
|
||||
```text
|
||||
All lines are at most 42 columns; every
|
||||
glyph is a CP437 byte >= 0x20 (checked
|
||||
@@ -87,56 +85,6 @@ with Python cp437). Ruler, not printed:
|
||||
1 2 3 4
|
||||
123456789012345678901234567890123456789012
|
||||
|
||||
--- 1. ntfy priority 4 (high)
|
||||
╔═ HIGH ═════════════════════════════════╗
|
||||
║ [!] Disk almost full ║
|
||||
╟────────────────────────────────────────╢
|
||||
║ /var is at 94% on nas01 ║
|
||||
║ ║
|
||||
║ Tags: nas01 ║
|
||||
╚═══════════════ alerts · 29 Nov 21:04 ══╝
|
||||
|
||||
[qr: grafana.lan/d/disk]
|
||||
Open dashboard
|
||||
|
||||
[image 384 dots: graph.png]
|
||||
- - - - - - - partial cut - - - - - - - -
|
||||
Input: the brief's example message.
|
||||
Row 2 prints bold. [!] is the "warning"
|
||||
tag; "nas01" has no marker, so it is
|
||||
listed. **/var** *94%* prints plain.
|
||||
The QR is the click URL. The view action
|
||||
has the same URL, so its label is the
|
||||
caption. [...] lines are real graphics.
|
||||
|
||||
--- 2. ntfy priority 5 (max/urgent)
|
||||
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ URGENT ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
|
||||
╔════════════════════════════════════════╗
|
||||
║ (!) Backup FAILED on nas01 ║
|
||||
╠════════════════════════════════════════╣
|
||||
║ Job nightly-offsite exited with code 2 ║
|
||||
║ after 3h12m. Last good run: 2 days ║
|
||||
║ ago. ║
|
||||
╚══════════════ backups · 29 Nov 21:04 ══╝
|
||||
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
|
||||
Row 3 prints bold and inverted. (!) is
|
||||
the "rotating_light" tag.
|
||||
|
||||
--- 3. ntfy priority 3 (default)
|
||||
┌─ [√] Nightly backup ───────────────────┐
|
||||
│ restic: 2.1 GB added in 14m 02s, 0 │
|
||||
│ errors. │
|
||||
│ │
|
||||
│ Tags: restic │
|
||||
└────────────── backups · 29 Nov 03:12 ──┘
|
||||
The title prints bold in the top border.
|
||||
|
||||
--- 4. ntfy priority 1-2 (no box)
|
||||
── backups · 29 Nov 03:12 ────────────────
|
||||
Prune finished
|
||||
41 snapshots kept, 3 removed.
|
||||
"Prune finished" (the title) is bold.
|
||||
|
||||
--- 12. Rate-limit digest (phase 4)
|
||||
┌─ ntfy digest · 6 held ─────────────────┐
|
||||
│ 21:05 [!] Disk almost full │
|
||||
@@ -158,89 +106,15 @@ Use · ∙ ■ » √ ° instead.
|
||||
## API
|
||||
|
||||
All /api/v1 routes keep the existing Bearer JWT, rate limiter and error shape {"error","details"}. Successful print responses keep today's 202 body plus a Location header:
|
||||
{"id":"job_01kbx4n6m3ex8tq0wq3r5vrzq1","status":"queued","created_at":"2026-11-29T21:04:05Z"}
|
||||
{"id":"job_01kbx4n6m3ex8tq0wq3r5vrzq1","status":"queued","source":"print","created_at":"2026-11-29T21:04:05Z"}
|
||||
|
||||
==== Blocks in POST /api/v1/print ====
|
||||
==== PHASE 4: configuration ====
|
||||
|
||||
box, rule, kv and list, the preview (POST /api/v1/preview, `uberbringer preview`) and format.max_lines are built; docs/api.md § Blocks and § Preview a receipt describe them. Validation problems name nested elements, e.g. elements[0].children[3] (qr). Still to come:
|
||||
Keys go through internal/pkg/config as today: strict keys in the file, an UBERBRINGER_<SECTION>_<KEY> variable for each setting. [format] and the card settings [ntfy.format] and [ntfy.markers] are built (README § Configuration).
|
||||
|
||||
image (phase 3)
|
||||
- New field optional: true. If the image can't be fetched or decoded, the receipt prints "[image unavailable]" instead of failing the whole job.
|
||||
|
||||
==== Modules ====
|
||||
|
||||
Built in phase 2 (docs/api.md § Modules): GET /api/v1/modules, POST /api/v1/print/{module} and /api/v1/preview/{module} (202, 204 for ErrSkip, 400 invalid_payload, 404 module_not_found, 422 module_failed, 503 as on /print), ?copies, ?printer reserved for "default", and the note module. Payloads decode with modules.DecodeStrict, which reports every problem. Still to come:
|
||||
- GET /api/v1/modules also lists notify and ntfy once they are registered in newModules (internal/app/uberbringer/modules.go):
|
||||
{"name":"notify","description":"Notification card from title, message, priority and tags"},
|
||||
{"name":"ntfy","description":"One ntfy message object, e.g. the CLI's $NTFY_RAW"}
|
||||
- 403: the token's scope does not include this module (phase 3). It needs a new code in server/errors.go and docs/api.md.
|
||||
- 422 stays a module bug; ntfy and notify print the fallback receipt instead of building an invalid job.
|
||||
|
||||
==== PHASE 3: notifications ====
|
||||
|
||||
notify payload (strict; for scripts, cron jobs and phone shortcuts):
|
||||
POST /api/v1/print/notify
|
||||
{"title":"Disk almost full","message":"/var is at 94% on nas01","priority":"high","tags":["warning","nas01"],
|
||||
"topic":"alerts","click":"https://grafana.lan/d/disk","markdown":false}
|
||||
- Optional fields:
|
||||
- time: Unix seconds or RFC 3339. Default now.
|
||||
- actions: up to 3 [{label, url}].
|
||||
- image: a URL.
|
||||
- priority is 1-5, or one of min, low, default, high, max, urgent.
|
||||
- Minimal call: {"message":"Back at 3"} prints a priority-3 single box.
|
||||
|
||||
ntfy payload: one ntfy subscribe-API message, exactly as received.
|
||||
- Decoded leniently: unknown fields are ignored, so new ntfy versions keep working.
|
||||
POST /api/v1/print/ntfy
|
||||
{"id":"sPs71M8A2Tq9","time":1764450245,"event":"message","topic":"alerts","title":"Disk almost full",
|
||||
"message":"**/var** is at *94%* on nas01","content_type":"text/markdown","priority":4,"tags":["warning","nas01"],
|
||||
"click":"https://grafana.lan/d/disk",
|
||||
"actions":[{"id":"a1","action":"view","label":"Open dashboard","url":"https://grafana.lan/d/disk","clear":false}],
|
||||
"attachment":{"name":"graph.png","type":"image/png","size":33848,"expires":1764461045,"url":"https://ntfy.example.com/file/sPs71M8A2Tq9.png"}}
|
||||
- 202: prints mockup 1.
|
||||
- 204: open, keepalive, poll_request, message_delete and message_clear events, and encoding=base64.
|
||||
|
||||
ntfy CLI recipe (works after phase 3; no jq). Linux, in ~/.config/ntfy/client.yml or /etc/ntfy/client.yml:
|
||||
default-host: https://ntfy.sh
|
||||
default-token: tk_...
|
||||
subscribe:
|
||||
- topic: alerts
|
||||
command: |
|
||||
printf '%s' "$NTFY_RAW" | curl -fsS -X POST \
|
||||
-H "Authorization: Bearer $UBERBRINGER_TOKEN" -H "Content-Type: application/json" \
|
||||
--data-binary @- https://printer.example.com/api/v1/print/ntfy
|
||||
if:
|
||||
priority: default,high,urgent
|
||||
|
||||
Windows: cmd.exe breaks %NTFY_RAW%, so use PowerShell:
|
||||
command: powershell -NoProfile -Command "Invoke-RestMethod -Method Post -Uri https://printer.example.com/api/v1/print/ntfy -Headers @{Authorization=('Bearer ' + $env:UBERBRINGER_TOKEN)} -ContentType 'application/json' -Body ([Text.Encoding]::UTF8.GetBytes($env:NTFY_RAW))"
|
||||
|
||||
Scoped tokens:
|
||||
- uberbringer token --subject ntfy-cli --modules ntfy,notify adds the claim "mod":["ntfy","notify"].
|
||||
- A token with that claim may only call:
|
||||
- POST /api/v1/print/{m} and /api/v1/preview/{m} for the listed modules
|
||||
- GET /api/v1/modules
|
||||
- GET /api/v1/jobs/{id}
|
||||
- Anything else returns 403 {"error":"token is limited to modules ntfy, notify"}.
|
||||
- Tokens without the claim keep full access, so existing tokens keep working.
|
||||
|
||||
Job status:
|
||||
- GET /api/v1/jobs/{id} gains "source", e.g. "module:ntfy" or, in phase 4, "ntfy:home".
|
||||
|
||||
==== PHASE 3-4: configuration ====
|
||||
|
||||
Keys go through internal/pkg/config as today: strict keys in the file, an UBERBRINGER_<SECTION>_<KEY> variable for each setting, and [format] max_lines, timezone and time_layout already built.
|
||||
|
||||
[ntfy.format] # phase 3
|
||||
style = "auto" # auto | box | compact
|
||||
max_lines = 40
|
||||
qr = "all" # all | first | none
|
||||
images = true
|
||||
markdown = true
|
||||
updates = "print" # print | skip (sequence_id updates)
|
||||
[ntfy.markers] # optional overrides; "" hides a tag
|
||||
backup = "[B]"
|
||||
[ntfy] # phase 4
|
||||
[ntfy.format]
|
||||
updates = "print" # print | skip: a message replacing one the subscriber printed
|
||||
[ntfy]
|
||||
state_dir = "/var/lib/uberbringer"
|
||||
[[ntfy.subscriptions]]
|
||||
name = "home"
|
||||
@@ -270,8 +144,8 @@ GET /healthz (phase 4) adds a field. The HTTP status still depends only on the p
|
||||
|
||||
LAYERS (each calls only downward)
|
||||
- server (Fiber v3 handlers) -> modules (payload to receipt.Job) -> receipt (blocks, layout, render, preview) -> escpos (bytes, code pages, interpreter).
|
||||
- internal/pkg/ntfy holds the ntfy wire types (phase 3) and the subscriber (phase 4). modules imports it for the Message type. serve.go connects the subscriber to modules through a callback, so ntfy never imports modules.
|
||||
- printqueue is unchanged apart from Submit(job, Meta).
|
||||
- internal/pkg/ntfy holds the ntfy wire types (built) and the subscriber (phase 4). modules imports it for the Message type. serve.go connects the subscriber to modules through a callback, so ntfy never imports modules.
|
||||
- printqueue takes Submit(job, Meta) (built).
|
||||
|
||||
INVARIANTS (all match the current code)
|
||||
1. receipt.Job stays printer-neutral. Blocks are sized at render time from Options.Columns or Profile.Columns(font). The same job therefore prints correctly on a TM-T88IV, TM-T88VII or TM-m50II, and on several printers later.
|
||||
@@ -283,7 +157,7 @@ INVARIANTS (all match the current code)
|
||||
- one level of nesting only
|
||||
3. Layout never fails on a valid job. Widths clamp, titles are cut with "...", and over-long words split the way wrap() already splits them. The only new render-time failure is the [format].max_lines backstop (default 2000).
|
||||
4. Renderer.Render is still the only path to printer bytes, and still all-or-nothing.
|
||||
5. New code never emits raw ESC/POS. Payload text only ever lands in string fields of elements. The raw element stays available on /print only, and scoped tokens cannot reach it.
|
||||
5. New code never emits raw ESC/POS. Payload text only ever lands in string fields of elements. The raw element stays available on /print only, to tokens issued with --raw.
|
||||
6. /print stays strictly decoded (DisallowUnknownFields). A byte-compatibility test pins today's bytes.
|
||||
|
||||
DATA FLOW
|
||||
@@ -294,101 +168,22 @@ DATA FLOW
|
||||
- /print/{module}: module.Build(body, Env) -> Validate (a failure here is a module bug, 422) -> Submit(job, Meta{Source: "module:<name>"}).
|
||||
- Subscriber (phase 4): ntfy stream -> skip, dedupe, filter, rate limit -> modules.FromNtfy -> Card -> Validate -> Submit(job, Meta{Source: "ntfy:<sub>", Ref: <ntfy id>}).
|
||||
|
||||
KEY TYPES (new or changed; the escpos interpreter, the blocks, Renderer.Preview and the module layer are built)
|
||||
KEY TYPES (the blocks, the preview, the module layer, the notification card and the ntfy wire types are built; docs/api.md and design.md describe them)
|
||||
|
||||
receipt
|
||||
Element gains Optional bool on image (phase 3)
|
||||
func StripEmoji(s string) string (phase 3)
|
||||
|
||||
modules (built: Env, Module, ErrSkip, PayloadError, Registry, DecodeStrict, Note; phase 3 adds the rest)
|
||||
Env gains Card CardOptions
|
||||
type Notice struct{ ID, Topic, Title, Message string; Markdown bool; Priority int; Tags []string;
|
||||
Time time.Time; Links []Link; Image string; File *File; Updated bool }
|
||||
func FromNtfy(m ntfy.Message) (Notice, error) // ErrSkip for non-message events
|
||||
func Card(n Notice, o CardOptions, env Env) receipt.Job
|
||||
modules (built)
|
||||
type Notice; type CardOptions (zero value is the default; Env.Card carries it)
|
||||
func FromNtfy(m ntfy.Message) (Notice, error) // ErrSkip for non-message events and base64 bodies
|
||||
func Card(n Notice, o CardOptions, env Env) (receipt.Job, error) // the job always prints; a *FallbackError comes with the plain receipt, for the caller to log and report
|
||||
|
||||
ntfy
|
||||
type Message, Action, Attachment // mirror ntfy model/model.go
|
||||
func (m Message) Priority() int // 0 or missing becomes 3
|
||||
type Message, Action, Attachment // built
|
||||
type Subscriber // phase 4
|
||||
func (s *Subscriber) Run(ctx context.Context, handle func(context.Context, Message) error) error
|
||||
|
||||
printqueue
|
||||
Submit(job receipt.Job, meta Meta) (Status, error)
|
||||
type Meta struct{ Source, Ref string }
|
||||
Status gains Source
|
||||
printqueue (built)
|
||||
Submit(job receipt.Job, meta Meta) (Status, error); type Meta struct{ Source, Ref string }; Status.Source
|
||||
|
||||
BLOCK LAYOUT (receipt/blocklayout.go and receipt/glyphs.go)
|
||||
box, rule, kv and list are built; docs/design.md records their rules.
|
||||
|
||||
TEXT NORMALIZATION (receipt/normalize.go)
|
||||
Built: NFC, the fold table and one '?' per emoji sequence on /print. Phase 3 adds StripEmoji for modules: it maps a few typed emoji to markers (⚠ to [!], ✅ to [√], ❌ to [x], 🚨 to (!), 👍 to (+1)), then removes the remaining emoji instead of printing '?'.
|
||||
|
||||
NTFY AND NOTIFY CARD (modules/card.go)
|
||||
The same card is used for /print/notify, /print/ntfy and the subscriber.
|
||||
|
||||
Skip
|
||||
- event other than "message", or encoding = "base64": ErrSkip, which returns 204.
|
||||
|
||||
Priority
|
||||
- A missing or 0 priority counts as 3.
|
||||
|
||||
Style ladder (style = auto; box and compact force one form):
|
||||
- 5: a dark rule "URGENT", a double box, the title row bold and inverted, a double divider, the body, the footer, then another dark rule.
|
||||
- 4: a double box with "HIGH" in the top border, a bold title row, a single divider, then the body.
|
||||
- 3: a single box with the bold title set into the top border.
|
||||
- 1-2: a left-labelled rule "topic · time", then a bold title line and the body, with no box.
|
||||
|
||||
Title
|
||||
- The title; if empty, the topic; if that is empty too, "Notification".
|
||||
- Up to 2 tag markers go in front of it.
|
||||
- " (updated)" goes after it when sequence_id differs from id. With updates = skip, such messages are not printed.
|
||||
|
||||
Tag markers (exact lowercase match)
|
||||
- warning → [!]
|
||||
- rotating_light, fire, boom → (!)
|
||||
- white_check_mark, heavy_check_mark, ballot_box_with_check → [√]
|
||||
- x, negative_squared_cross_mark, no_entry, no_entry_sign → [x]
|
||||
- information_source → (i)
|
||||
- question → (?)
|
||||
- +1, thumbsup → (+1)
|
||||
- -1, thumbsdown → (-1)
|
||||
- loudspeaker, mega → <!>
|
||||
- tada → \o/
|
||||
- skull → x_x
|
||||
- hourglass → (...)
|
||||
[ntfy.markers] in the config can override any marker, and "" hides a tag. Any other tag prints as text on a "Tags: a, b" row.
|
||||
|
||||
Body
|
||||
- The message, with the markdown subset applied when content_type is text/markdown (or markdown: true on notify):
|
||||
- #, ## and ### headings → bold lines
|
||||
- - * + items → · list
|
||||
- 1. items → numbered list
|
||||
- > quotes → a "│ " prefix
|
||||
- ``` fences → printed as written
|
||||
- --- → a divider
|
||||
- inline ** __ * _ ` ~~ → removed
|
||||
- [t](u) → t, with u added to the links
|
||||
-  → [image: a]
|
||||
- The body is capped at [ntfy.format].max_lines (default 40), followed by "... N more lines".
|
||||
- The "You received a file: X" placeholder becomes a "File" row.
|
||||
|
||||
Footer
|
||||
- "<topic> · <time>", using [format].timezone and time_layout (default "02 Jan 15:04").
|
||||
|
||||
Links
|
||||
- The links are the click URL plus view actions (http or https), with duplicates removed, at most 3.
|
||||
- qr = all (default): every link prints as a centred QR code (size 5, correction M) with a Font B caption, the action's label or else host/path.
|
||||
- qr = first prints only the first link as a QR code and the others as "» label" plus the URL; qr = none prints them all as text.
|
||||
- http, broadcast and copy actions are never printed, because their headers and body can hold secrets.
|
||||
|
||||
Attachments
|
||||
- An image (type image/*, or a .png, .jpg, .jpeg, .gif or .webp name) that has not expired, with images = true: an image element with optional:true, 384 dots wide, centred. The renderer fetches it through safehttp.
|
||||
- Otherwise: a kv row such as "File ... name (33 KB)".
|
||||
- icon is ignored.
|
||||
|
||||
Failures
|
||||
- Card never fails. Any internal error produces the plain fallback receipt: title, message, topic and time.
|
||||
The subscriber marks and skips updates itself (Dedupe and state below); Card prints the notice it is given.
|
||||
|
||||
SUBSCRIBER (phase 4, internal/pkg/ntfy)
|
||||
|
||||
@@ -405,6 +200,7 @@ Cursor
|
||||
|
||||
Dedupe and state
|
||||
- A ring of the last 512 ids is persisted. It drops ntfy 2.31+ same-second repeats and the overlap after a reconnect.
|
||||
- Updates: the sequence IDs of printed messages are remembered with the ids. A message whose sequence was printed before sets Notice.Updated, so its card shows "(updated)", or with updates = "skip" it is left out. The module routes print every message plain (design.md).
|
||||
- State is JSON in state_dir, written as temp file, then fsync, then rename. It is written at most once a second, and on shutdown.
|
||||
|
||||
Reconnects
|
||||
@@ -431,94 +227,6 @@ Images and logging
|
||||
|
||||
## Phases
|
||||
|
||||
### Phase 3: Notifications, the notify and ntfy modules (3 days)
|
||||
|
||||
**Goal.** ntfy prints with minimal effort. The ntfy CLI posts $NTFY_RAW unchanged, and scripts can send {title, message, priority, tags}. Both print the same priority-styled card. Integration tokens can't send raw ESC/POS.
|
||||
|
||||
**Work.**
|
||||
|
||||
internal/pkg/ntfy (new)
|
||||
- message.go: Message, Action and Attachment, following ntfy model.go, plus Priority().
|
||||
|
||||
internal/pkg/modules
|
||||
- notice.go: the Notice type. Priority names min, low, default, high, max and urgent map to 1-5.
|
||||
- notify.go: strict decode with DecodeStrict into a Notice.
|
||||
- notify and ntfy are registered in newModules (internal/app/uberbringer/modules.go).
|
||||
- ntfy.go: lenient decode into ntfy.Message, then FromNtfy into a Notice. It returns ErrSkip for events other than message and for encoding=base64.
|
||||
- card.go: Card(Notice, CardOptions, Env) builds the receipt.Job using the priority ladder, title and markers, body cap, footer, links and QR, the attachment image or File row, and the updates policy.
|
||||
- markers.go: the tag and typed-emoji marker table, merged with the [ntfy.markers] overrides, then StripEmoji.
|
||||
- markdown.go: the line-level subset described in the architecture section, about 150 lines, with no new dependency.
|
||||
- fallback.go: a plain receipt (title, message, topic, time). Card falls back to it on any internal error.
|
||||
|
||||
internal/pkg/receipt
|
||||
- image `optional`: loadImages returns a placeholder for an optional image that fails, and the renderer prints "[image unavailable]".
|
||||
- StripEmoji is exported.
|
||||
|
||||
internal/pkg/printqueue
|
||||
- Submit(job, Meta{Source, Ref}).
|
||||
- Status.Source.
|
||||
- Source and ref are added to the worker logs.
|
||||
- The caller in server is updated: the Jobs interface and s.submit, which /print and the module routes share; module routes pass Meta{Source: "module:<name>"}.
|
||||
|
||||
internal/app/uberbringer/server
|
||||
- auth.go: parse the optional "mod" claim and enforce the allowed routes, returning 403 otherwise.
|
||||
- handleJob: shows source.
|
||||
|
||||
internal/app/uberbringer
|
||||
- cli.go: `token --modules ntfy,notify`.
|
||||
|
||||
internal/pkg/config
|
||||
- [ntfy.format] (style, max_lines, qr, images, markdown, updates) and [ntfy.markers], with validation.
|
||||
|
||||
Docs
|
||||
- docs/api.md: notify and ntfy sections under § Modules, the ntfy CLI recipe for Linux client.yml and Windows PowerShell, token scopes and their 403 code, and a warning that public ntfy.sh topics can be guessed.
|
||||
- README: `token --modules` under Command line and [ntfy.format] and [ntfy.markers] under Configuration. Update configs/config.example.toml.
|
||||
|
||||
**Tests.**
|
||||
|
||||
internal/pkg/modules
|
||||
- Card golden previews:
|
||||
- priorities 1-5 × style auto, box and compact (mockups 1-4)
|
||||
- the brief's example message rendered exactly
|
||||
- Markers: built-in table, a config override, hiding a tag with "", and the unmapped tag row.
|
||||
- Markdown subset golden tests, plus FuzzMarkdown: no panic, and every line fits.
|
||||
- FromNtfy table:
|
||||
- unknown fields ignored
|
||||
- priority 0 or missing becomes 3
|
||||
- missing title falls back to the topic
|
||||
- the 'You received a file' placeholder becomes a File row
|
||||
- an image attachment becomes an optional image; an expired one becomes a File row
|
||||
- an attachment with no type is sniffed by extension
|
||||
- sequence_id gives "(updated)", or a skip with updates=skip
|
||||
- non-message and base64 events give ErrSkip
|
||||
- http, broadcast and copy actions never print: assert their URL, header and body strings appear nowhere in the preview.
|
||||
- A body longer than max_lines gives '... N more lines'.
|
||||
- Typed ⚠ becomes [!], and other emoji are stripped.
|
||||
- Links: deduped, at most 3; qr=first, all and none.
|
||||
- notify: strict decode errors.
|
||||
- Fallback: Card with a forced internal error still returns a valid job.
|
||||
|
||||
internal/pkg/receipt
|
||||
- An optional image that fails prints the placeholder, while a non-optional failure still fails the whole job and produces nothing.
|
||||
|
||||
internal/app/uberbringer/server
|
||||
- Scoped token:
|
||||
- 202 on /print/ntfy
|
||||
- 403 on /print and /print/note
|
||||
- 200 on GET /jobs/{id}
|
||||
- An unscoped token is unchanged.
|
||||
- 204 for a keepalive body.
|
||||
|
||||
internal/pkg/printqueue
|
||||
- Meta appears in Status.
|
||||
|
||||
**Done when.**
|
||||
|
||||
- On the owner's machine, the ntfy CLI recipe prints mockup 1 for the brief's example message and mockups 2-4 for priority 5, 3 and 1.
|
||||
- /api/v1/preview/ntfy and `uberbringer preview --module ntfy` show the same output.
|
||||
- A token from `uberbringer token --modules ntfy` gets 403 on /api/v1/print.
|
||||
- The full gate passes (CLAUDE.md lists it).
|
||||
|
||||
### Phase 4: Built-in ntfy subscriber (5 days)
|
||||
|
||||
**Goal.** No client code and no extra programs: add [[ntfy.subscriptions]] to the config and the phone's ntfy app becomes the only client. Restarts and outages must not lose a flood's worth of paper or reprint old messages, and nothing but urgent messages prints during quiet hours.
|
||||
|
||||
Reference in new issue
Block a user