CCTV Street View fallback: the browser's pose at the catalog position

The fallback keeps the catalog position but takes heading, field of view
and pitch from the request again, as before, clamped as before. A catalog
camera with no pose (every world-cameras row on main) otherwise asked
Google for heading 0, pitch 0, FOV 80 while the browser draws it at the
id-hash heading, pitch -17 and FOV 74, and a calibrated camera lost its
calibration. Cost and the per-IP budget are unchanged.

- The Street View budget is built per proxy, so tests no longer depend on
  GEV_RATELIMIT_GOOGLE_PER_MIN in the shell; the fixture pins it.
- New tests: a pose-less catalog camera, and the per-IP budget (no call
  without a key, the cap, a separate budget per address).
- The client no longer sends lat/lon on /frame.
- CURRENT-STATE, the changelog fragment and SECURITY.md say the fallback
  has its own per-client limit, and that unlisted (seed) cameras get the
  placeholder.
This commit is contained in:
German Khokhlov committed 2026-11-19 19:06:53 +04:00
1 parent f579b23f52
commit 11e1c9d26d
8 files changed
+235 -36

No files matched your search

+31 -20
View File
@@ -21,19 +21,6 @@ import { createHlsPuller } from './cctv/stream.js';
import { googleServerApiKey } from './places/google-key.js';
import { clientKey, makeCostRateLimiter } from './common/rate-limit.js';
export { CCTV_FRAME_FETCH_TIMEOUT_MS, fetchCctvImageFromUpstream };
let _streetViewRateLimiter;
/**
* Per-IP budget for the Street View fallback, on the same setting as the
* other Google routes (GEV_RATELIMIT_GOOGLE_PER_MIN; 0 disables it).
*/
function streetViewRateLimiter() {
if (_streetViewRateLimiter === undefined)
_streetViewRateLimiter = makeCostRateLimiter(
process.env.GEV_RATELIMIT_GOOGLE_PER_MIN,
120,
);
return _streetViewRateLimiter;
}
/**
* Vite plugin: CCTV camera proxy with source registry, frame/media serving,
@@ -96,6 +83,22 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
};
};
/**
* Per-IP budget for the Street View fallback, one per proxy, on the same
* setting as the other Google routes (GEV_RATELIMIT_GOOGLE_PER_MIN; 0
* disables it). Built on first use, after the standalone env has loaded.
* undefined = not built yet; null = the explicit 0 opt-out.
*/
let streetViewBudget;
const streetViewRateLimiter = () => {
if (streetViewBudget === undefined)
streetViewBudget = makeCostRateLimiter(
process.env.GEV_RATELIMIT_GOOGLE_PER_MIN,
120,
);
return streetViewBudget;
};
/**
* Fetch a Google Street View static image as a fallback frame. Server-side
* call, never reaches the browser — prefers GOOGLE_MAPS_SERVER_API_KEY
@@ -524,6 +527,13 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
const source = sourceById.get(cameraId);
const label = url.searchParams.get('label') || source?.name || cameraId;
const city = url.searchParams.get('city') || source?.city || '';
// The view follows the pose the browser draws (calibration included);
// the position never comes from the query (see the Street View fallback).
const heading = Number(
url.searchParams.get('heading') || source?.headingDeg,
);
const fov = Number(url.searchParams.get('fov') || source?.fovDeg);
const pitch = Number(url.searchParams.get('pitch') || source?.pitchDeg);
// Only use server-registered upstream URLs — never accept client-supplied URLs
// (prevents SSRF via ?upstream= query parameter)
@@ -557,8 +567,9 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
// request (whose client this server cannot see) gets the placeholder,
// as if no key were configured. Any forwarding header counts, even an
// empty one.
// It is also only for catalog cameras, framed from the catalog (never
// a spot the query names), within the per-IP Google budget.
// It is also only for catalog cameras, at the catalog position (never a
// spot the query names; the query sets only the view), within the per-IP
// Google budget.
const forwarded = PROXY_SIGNALS.some(
(name) => req.headers?.[name] !== undefined,
);
@@ -571,11 +582,11 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
(googleBudget && !googleBudget(clientKey(req)))
? null
: await streetViewFallback({
lat: Number(source.lat),
lon: Number(source.lon),
heading: Number(source.headingDeg),
fov: Number(source.fovDeg),
pitch: Number(source.pitchDeg ?? -10),
lat: source.lat,
lon: source.lon,
heading,
fov,
pitch,
});
if (sv?.ok) {
setHealth(cameraId, {