Add plays from photos (OpenRouter or Claude), library, editor, compose; full-page PDF #2

Merged
reudy merged 2 commits from feat/library-uploads into main 2026-11-04 16:39:46 +01:00
Member

A reader for play scripts, with a library that people can add their own plays to from photos of the pages.

What's in it

Reading. A library of plays, then for each play: choice of font, size and colours; pick your character to highlight your lines and jump between them; running text or the original typescript lines; reading mode; PDF export of your own copy.

Adding plays (needs the shared UPLOAD_PASSWORD):

  1. Upload a photo of each page. The browser shrinks them to ≤1.15 MP JPEG and strips EXIF.
  2. The server sends one request per page to a vision model, which writes the script markup directly. It uses OpenRouter when OPENROUTER_API_KEY is set (default google/gemini-3.1-flash-lite, about $0.0015 a page, any image model via OPENROUTER_MODEL). Otherwise it uses the Anthropic API with ANTHROPIC_API_KEY (claude-haiku-5-5). The pages are then stitched together:
    • speaker spellings are unified (LÍDA / Lida: → Lída);
    • gaps in the page numbers become "missing page" notices;
    • pages that failed are flagged.
  3. The editor shows the text beside the photos and lists what to check: [?] readings, names that appear only once, failed pages. Then publish.

PDF export fix. Text now flows from one original page to the next and prints at the on-screen size (19 px ≈ 14 pt). A4 sheets are full instead of half empty, and there are page numbers in the footer. The 1931 play is now 19 full pages, where before it was 24 half-empty pages at ~10 pt.

Deploy. docker-compose.yml + .env.example. A named volume plays holds the data and is seeded with the 1931 play on first start. Ports are on loopback by default.

Safety / cost

  • Every write needs the password. A wrong password gets a 1 s delay. Unpublished plays return 404 without the password.
  • DAILY_PAGE_LIMIT (default 300 pages a day across all users) caps API spend if the password leaks.
  • Path traversal is blocked for both static files and play ids. A CSP is set. Images must be JPEG, and size limits apply.
  • Once the text has been edited by hand, transcription is refused, so it can't overwrite corrections.

Tested

  • npm test: 20 tests covering the parser, transcription assembly, both providers (OpenRouter through a fake fetch, including retries and error messages), and the API end to end with a stub provider.
  • One request to the real OpenRouter endpoint with an invalid key returns "OpenRouter key rejected", so the request format and error handling work against the live API.
  • Playwright against the real server, using a stub Anthropic endpoint through ANTHROPIC_BASE_URL:
    • wrong and right password;
    • upload of 3 images, sorted by file name;
    • transcription progress, then editor checks;
    • fix the text, publish, and view it as a visitor;
    • role highlighting;
    • old /?postava= link;
    • PDF export;
    • mobile layouts.
  • podman-compose up -d --build on the box: healthcheck OK and the volume is seeded.

Not tested:

  • Real transcription quality. No API key or credit is configured here, so how well the models read Czech typescript is unverified.
  • HEIC photos from iPhones. These open in Safari but probably not in Chrome, and the app tells the user so.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt

A reader for play scripts, with a library that people can add their own plays to from photos of the pages. ## What's in it **Reading.** A library of plays, then for each play: choice of font, size and colours; pick your character to highlight your lines and jump between them; running text or the original typescript lines; reading mode; PDF export of your own copy. **Adding plays** (needs the shared `UPLOAD_PASSWORD`): 1. Upload a photo of each page. The browser shrinks them to ≤1.15 MP JPEG and strips EXIF. 2. The server sends one request per page to a vision model, which writes the script markup directly. It uses OpenRouter when `OPENROUTER_API_KEY` is set (default `google/gemini-3.1-flash-lite`, about $0.0015 a page, any image model via `OPENROUTER_MODEL`). Otherwise it uses the Anthropic API with `ANTHROPIC_API_KEY` (`claude-haiku-5-5`). The pages are then stitched together: - speaker spellings are unified (LÍDA / Lida: → Lída); - gaps in the page numbers become "missing page" notices; - pages that failed are flagged. 3. The editor shows the text beside the photos and lists what to check: `[?]` readings, names that appear only once, failed pages. Then publish. **PDF export fix.** Text now flows from one original page to the next and prints at the on-screen size (19 px ≈ 14 pt). A4 sheets are full instead of half empty, and there are page numbers in the footer. The 1931 play is now 19 full pages, where before it was 24 half-empty pages at ~10 pt. **Deploy.** `docker-compose.yml` + `.env.example`. A named volume `plays` holds the data and is seeded with the 1931 play on first start. Ports are on loopback by default. ## Safety / cost - Every write needs the password. A wrong password gets a 1 s delay. Unpublished plays return 404 without the password. - `DAILY_PAGE_LIMIT` (default 300 pages a day across all users) caps API spend if the password leaks. - Path traversal is blocked for both static files and play ids. A CSP is set. Images must be JPEG, and size limits apply. - Once the text has been edited by hand, transcription is refused, so it can't overwrite corrections. ## Tested - `npm test`: 20 tests covering the parser, transcription assembly, both providers (OpenRouter through a fake `fetch`, including retries and error messages), and the API end to end with a stub provider. - One request to the real OpenRouter endpoint with an invalid key returns "OpenRouter key rejected", so the request format and error handling work against the live API. - Playwright against the real server, using a stub Anthropic endpoint through `ANTHROPIC_BASE_URL`: - wrong and right password; - upload of 3 images, sorted by file name; - transcription progress, then editor checks; - fix the text, publish, and view it as a visitor; - role highlighting; - old `/?postava=` link; - PDF export; - mobile layouts. - `podman-compose up -d --build` on the box: healthcheck OK and the volume is seeded. **Not tested:** - Real transcription quality. No API key or credit is configured here, so how well the models read Czech typescript is unverified. - HEIC photos from iPhones. These open in Safari but probably not in Chrome, and the app tells the user so. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
agent added 1 commit 2026-11-03 10:44:12 +01:00
- 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
agent changed title from Add plays from photos (Claude), library, editor, compose; full-page PDF to Add plays from photos (OpenRouter or Claude), library, editor, compose; full-page PDF 2026-11-04 16:38:26 +01:00
agent added 1 commit 2026-11-04 16:38:27 +01:00
A Claude subscription can't be used by the app, so let it use any cheap
vision model on OpenRouter instead (default google/gemini-3.1-flash-lite,
OPENROUTER_MODEL to change). The Anthropic API stays available as the
second choice. Both providers share the prompt and live behind one
{ name, model, transcribe } interface in server/providers.mjs; OpenRouter
retries 408/429/5xx and network errors and turns 401/402/404 into
messages the editor can show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
reudy merged commit 3f2cf95f1d into main 2026-11-04 16:39:46 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/theater-reader#2
No description provided.