mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
- 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.
57 lines
2.1 KiB
JavaScript
57 lines
2.1 KiB
JavaScript
import { resolveGoogleServerKey } from '../../../scripts/google-server-key.mjs';
|
|
|
|
/**
|
|
* Default GEV_RATELIMIT_GOOGLE_PER_MIN for the Places and Geocoding window
|
|
* and the separate CCTV Street View window, in requests per minute per IP.
|
|
* The Pinokio build sets the same default in pinokio/_ENVIRONMENT.
|
|
* `.env.example` suggests 60 for hosts other than localhost.
|
|
*/
|
|
export const GOOGLE_DEFAULT_PER_MIN = 120;
|
|
|
|
/**
|
|
* Optional Google place context is an empty capability when no key is present,
|
|
* not a server outage. Returning 200 keeps a deliberately keyless session out
|
|
* of the browser error console while preserving an explicit configured flag.
|
|
*/
|
|
export function keylessGooglePlacesResponse(apiKey) {
|
|
if (String(apiKey ?? '').trim()) return null;
|
|
return {
|
|
statusCode: 200,
|
|
payload: { configured: false, error: null, places: [] },
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Geocoding speaks Google's own response shape rather than the `places: []`
|
|
* contract its two siblings use, because the browser adapters read `status`
|
|
* and `results` directly. The keyless capability reads the same way: a status
|
|
* that is not `OK` and no results, which the adapters already treat as "this
|
|
* provider did not answer" and pass to the next geocoder in the chain.
|
|
*/
|
|
export function keylessGoogleGeocodeResponse(apiKey) {
|
|
if (String(apiKey ?? '').trim()) return null;
|
|
return {
|
|
statusCode: 200,
|
|
payload: {
|
|
configured: false,
|
|
status: 'REQUEST_DENIED',
|
|
results: [],
|
|
error: null,
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Google API key for the SERVER-SIDE calls (Places nearby/text search,
|
|
* geocoding, the CCTV Street View fallback). These never reach the browser, so
|
|
* this key can be restricted by server IP and scoped to Places API + Geocoding
|
|
* API + Street View Static API — while GOOGLE_MAPS_API_KEY stays
|
|
* referrer-restricted to Map Tiles + Maps JavaScript API for the browser
|
|
* (#33, #363). Splitting them is opt-in: unset, this falls back to the shared
|
|
* browser key, which then has to carry every API both sides use and cannot
|
|
* take a referrer restriction.
|
|
*/
|
|
export function googleServerApiKey() {
|
|
return resolveGoogleServerKey(process.env);
|
|
}
|