Skip to content

feat(web): scale param + de-duped, hardened screenshot/status API#475

Draft
mrosseel wants to merge 1 commit into
brickbots:mainfrom
mrosseel:feat/web-screenshot-status-api
Draft

feat(web): scale param + de-duped, hardened screenshot/status API#475
mrosseel wants to merge 1 commit into
brickbots:mainfrom
mrosseel:feat/web-screenshot-status-api

Conversation

@mrosseel

Copy link
Copy Markdown
Collaborator

Summary

Improves the web-server screenshot/status API in python/PiFinder/api_extensions.py and python/PiFinder/server.py:

  • ?scale=N on /api/screen — optional integer query param (clamped 1..8) that nearest-neighbor upscales the returned PNG, so docs/PR captures of the 128×128 screen stay crisp. scale=1 (default) is byte-for-byte the old behavior.
  • De-duplicated screenshot serving/image (server.py) and /api/screen both served shared_state.screen() as a PNG with slightly different fallbacks. Both now go through a single get_screen_png() helper. /image keeps its contract (200 image/png) so the web-remote live view is unaffected.
  • Hardened /api/status — each shared_state.* read is now wrapped individually. A dead/broken multiprocessing manager degrades gracefully: readable fields are still returned, with a clear error map of which reads failed, instead of a blanket 500. The happy path is unchanged (no error key when everything reads).

Testing

  • tests/test_api_extensions.py passes (6/6).
  • Added local smoke checks (not committed): scale sizing/clamping (1/4/99→8/0→1), nearest-neighbor pixel preservation, None/BrokenPipeError screen fallbacks, and a Flask test-client run of /api/status against a partly-broken shared state (returns 200 + partial data + error field) and /api/screen?scale=5 (640×640).
  • ruff check and ruff format --check clean on both changed files.

🤖 Generated with Claude Code

- /api/screen accepts an optional ?scale=N (integer, clamped 1..8) that
  nearest-neighbor upscales the PNG for crisp docs/PR captures; scale=1
  (default) is unchanged.
- Consolidate the duplicated screen-PNG logic into a shared
  get_screen_png() helper in api_extensions; /image now delegates to it,
  keeping the web-remote live-view contract (200 image/png).
- Harden /api/status: wrap each shared_state read so a dead/broken
  multiprocessing manager degrades to partial data plus a clear `error`
  field instead of a blanket 500.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jscheidtmann

Copy link
Copy Markdown
Collaborator

Those tests sound useful to have in the codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants