CCTV Street View budget: key the client before the camera wait, share the default

- The /frame handler reads the client's network key (IPv6 /64) before it
  awaits the camera, so a client that drops the connection is still
  charged to its own window instead of the shared fallback key.
- The budget is charged only after the Google key and finite catalog
  coordinates are confirmed, and the key is read once.
- Places and the CCTV window share one default (GOOGLE_DEFAULT_PER_MIN).
- Tests: the catalog-only test checks heading/fov/pitch from the query at
  the catalog location; the budget test covers unknown ids, forwarded
  requests and /64 grouping; a real-socket test covers a dropped
  connection. The duplicate pose test is removed.
- .env.example, SECURITY.md, CURRENT-STATE and the changelog fragment
  describe the separate per-IP window, the catalog position and the
  placeholder for seed cameras.
This commit is contained in:
German Khokhlov committed 2026-11-20 11:31:14 +04:00
1 parent 01368b95bf
commit 01d4a3f454
10 files changed
+175 -201

No files matched your search

+9 -8
View File
@@ -1990,14 +1990,12 @@ redirects on those hosts, are pinned by parsed URL to the agency's image
directory. Every `/api/cctv` route refuses cross-site browser requests but
accepts forwarding headers, so cameras work behind a reverse proxy; a forwarded
request skips the key-bearing Street View fallback and gets the placeholder. The
Street View fallback serves only catalog cameras, always at the catalog
position; coordinates a request supplies are ignored. Heading, field of view
and pitch come from the request, the pose the browser draws with calibration
included, and fall back to the catalog pose. A camera the server does not list,
such as a bundled seed camera the browser shows when the server catalog is
empty, gets the placeholder. The fallback has its own per-client limit on the
Google setting (`GEV_RATELIMIT_GOOGLE_PER_MIN`, default 120, `0` disables it);
a request over it gets the placeholder.
fallback answers only for cameras the server lists, at their catalog position,
so position calibration never reaches it. Heading, field of view (clamped to
20–120°) and pitch (clamped to −40–20°) come from the request, else from the
catalog pose. A bundled seed camera, shown when the server catalog is empty,
gets the placeholder. The fallback counts in its own per-IP Google window (see
the cost-bearing proxies below).
The CCTV layer draws only the cameras on or near the screen. Zoomed out, it
keeps one camera per ground cell sized to the view, preferring a healthy feed,
@@ -3529,6 +3527,9 @@ unaffected. `GEV_RATELIMIT_OPENAI_PER_MIN` and `GEV_RATELIMIT_GOOGLE_PER_MIN` ov
those; exactly `0` disables the limiter, while a value that cannot be read as a
number falls back to the default rather than to unlimited. Over-limit requests
receive a sanitized `429` with `Retry-After: 5` and never reach the provider.
The CCTV Street View fallback counts in a separate window with the Google cap.
An IPv6 /64 counts as one client. Over the cap, a frame gets the placeholder
image instead of a `429`.
Typed chat (`/api/openai/chat`, `/api/gemini/chat`) counts in its own window,
set by `GEV_RATELIMIT_OPENAI_CHAT_PER_MIN` and `GEV_RATELIMIT_GEMINI_CHAT_PER_MIN`.
Left unset, each takes its provider's resolved cap — `GEV_RATELIMIT_OPENAI_PER_MIN`