Let people add plays from photos; library, editor, compose; full-page PDF

- Replace the static nginx site with a small Node server: serves public/,
  stores plays on a /data volume and exposes a JSON API. Writes need a
  shared UPLOAD_PASSWORD; unpublished plays are hidden without it.
- Page photos (shrunk to <=1.15 MP JPEG in the browser) are transcribed
  one request per page by a Claude vision model (claude-haiku-5-5 by
  default, CLAUDE_MODEL to change) into the play markup, then stitched
  together: speaker spellings unified, gaps in page numbers marked as
  missing pages, failed pages flagged. DAILY_PAGE_LIMIT caps spend.
- New pages: library (play menu), add (upload + progress), editor (text
  next to the photos, checks for [?] readings and one-off names, publish,
  delete). The reader loads plays from the API and remembers the chosen
  role per play; old /?postava= links still work.
- PDF export: text now flows across original pages and prints at the
  on-screen size, so A4 sheets are full instead of half empty; page
  numbers in the footer.
- docker-compose.yml + .env.example for one-click deploys; the 1931 play
  moves to seed/ and is copied into an empty volume on first start.
- Tests: parser leniency, transcription assembly, API end to end with a
  stubbed Claude client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
This commit is contained in:
agent 2026-11-03 09:43:32 +00:00
parent 2608d10dd2
commit 46aa1236ed
32 changed files with 1761 additions and 160 deletions

View file

@ -1,22 +1,32 @@
# AGENTS.md — theater-reader
A static web app (plain HTML/CSS/ES modules, no build step) served by unprivileged nginx in a container.
A Node 22 server (`server/`) serving a no-build front end (`public/`, plain HTML/CSS/ES modules) and a JSON API for plays
kept on a volume. Transcription of page photos goes through the Anthropic SDK (`@anthropic-ai/sdk`, the only dependency).
UI language is Czech.
## Layout
- `public/index.html`, `app.js`, `app.css` — the app. UI language is Czech.
- `public/parse.js` — parser for the play markup, also used by the tests.
- `public/plays/index.json` — list of plays (`id`, `file`, `title`, `note`); a play selector appears once there is more than one.
- `public/plays/*.txt` — play texts in the markup below.
- `public/fonts/` — self-hosted woff2 (latin + latin-ext) and their OFL licences, generated by `tools/fetch_fonts.py`.
- `deploy/` — nginx config. `Dockerfile` at the root.
- `server/main.mjs`: HTTP server, routing, static files, auth (`x-upload-password` header vs `UPLOAD_PASSWORD`), daily page cap, background transcription job.
- `server/store.mjs`: plays on disk, `DATA_DIR/plays/<id>/{meta.json,play.txt,img/NNN.jpg}`. Atomic writes; per-play lock for meta updates.
- `server/transcribe.mjs`: one Claude request per photo (`transcribePage`), then `splitPage` → `normalizeSpeakers` → `assemble` into one play file. `server/prompt.mjs` holds the prompt, which teaches the markup below.
- `public/`: four pages: `index.html` library (`library.js`), `read.html` reader (`reader.js`), `add.html` upload (`add.js`: shrinks photos to ≤1.15 MP JPEG in the browser), `edit.html` editor (`edit.js`). `api.js` holds the fetch and password helpers. `parse.js` is the markup parser, shared with the server tests.
- `seed/`: plays copied into an empty data volume on first start.
- `public/fonts/`: self-hosted woff2 + OFL licences, made by `tools/fetch_fonts.py` (keep its `FAMILIES` and `FONTS` in `reader.js` in step).
## API
`GET /api/config`, `POST /api/login`, `GET|POST /api/plays`, `GET|PATCH|DELETE /api/plays/:id`, `GET|PUT /api/plays/:id/text`,
`GET|PUT /api/plays/:id/images/:n` (raw `image/jpeg` body), `POST /api/plays/:id/transcribe` (202, then poll the meta's `progress`).
Everything that writes needs the password. Unpublished plays answer 404 without it. Transcription refuses once the text has been
edited by hand, so it can't overwrite corrections.
## Run / test
- Dev port: **3010** on loopback. `podman build -t theater-reader . && podman run -d --name theater-reader -p 127.0.0.1:3010:8080 theater-reader`.
The admin previews with `ssh -p 14922 -L 3010:localhost:3010 <host>`.
- Tests (parser): `podman run --rm -v "$PWD":/app:ro,Z -w /app docker.io/library/node:22-alpine npm test`.
- Fonts: `python3 tools/fetch_fonts.py` re-downloads them; edit `FAMILIES` there and the `FONTS` list in `app.js` together.
- Dev port **3010** on loopback. Preview with `ssh -p 14922 -L 3010:localhost:3010 <host>`.
`podman-compose --env-file <file> up -d --build` (env file with `UPLOAD_PASSWORD`, and optionally `ANTHROPIC_API_KEY`, chmod 600, outside the repo).
- Tests (parser, transcription assembly, API end to end with Claude stubbed):
`podman run --rm -v "$PWD":/app:ro,Z -w /app docker.io/library/node:22-alpine npm test` (run `npm ci` in the same image first if `node_modules` is missing).
- To exercise the full UI without spending API credit, point `ANTHROPIC_BASE_URL` at a stub server that returns a Messages response.
## Play markup
@ -37,6 +47,6 @@ One directive per line; blank lines are ignored.
The text keeps the typescript's line breaks, spelling and missing spaces ("dobře.Ale"). The "running text" mode joins
hyphenated words (`nepří-` / `jemné`, also the typist's `ne -` / `spokojenců`) and adds the missing spaces. **A dash that
really is punctuation at the end of a line must be typed as `–` (en dash)**, or it gets joined to the next word.
`[?]` after a word marks an uncertain reading. The editor lists them.
To add a missing page, e.g. page 7, replace the `!7` line in `hra.txt` with `=7` and its content; the speaker on page 8's first
lines comes from whatever speech page 7 ends with.
To add a missing page to a play, e.g. page 7 of the 1931 play, open it in the editor and replace `!7` with `=7` and the page's text.