mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
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:
1 parent
01368b95bf
commit
01d4a3f454
10 files changed
+175
-201
No files matched your search
@@ -553,12 +553,14 @@ test('the Street View fallback frames catalog cameras only, from the catalog pos
|
||||
assert.deepEqual(streetView(), [], 'no Google call for an unknown id');
|
||||
|
||||
const steered = await app.call(
|
||||
`/frame/${STILL.id}?lat=48.85&lon=2.29&heading=90`,
|
||||
`/frame/${STILL.id}?lat=48.85&lon=2.29&heading=90&fov=74&pitch=-17`,
|
||||
);
|
||||
assert.equal(steered.headers['X-CCTV-Source'], 'streetview');
|
||||
const location = new URL(streetView()[0].url).searchParams.get('location');
|
||||
assert.equal(location, `${STILL.lat},${STILL.lon}`);
|
||||
assert.equal(new URL(streetView()[0].url).searchParams.get('heading'), '90');
|
||||
const sv = new URL(streetView()[0].url).searchParams;
|
||||
assert.equal(sv.get('location'), `${STILL.lat},${STILL.lon}`);
|
||||
assert.equal(sv.get('heading'), '90');
|
||||
assert.equal(sv.get('fov'), '74');
|
||||
assert.equal(sv.get('pitch'), '-17');
|
||||
});
|
||||
|
||||
test('the Street View fallback spends a per-IP Google budget, and only with a key', async (t) => {
|
||||
@@ -586,8 +588,27 @@ test('the Street View fallback spends a per-IP Google budget, and only with a ke
|
||||
assert.equal(streetViewCalls(), 0);
|
||||
|
||||
process.env.GOOGLE_MAPS_SERVER_API_KEY = 'fixture-key';
|
||||
// Neither an unknown id nor a forwarded request spends the window.
|
||||
assert.equal(
|
||||
(await app.call('/frame/not-a-camera', {}, first)).headers['X-CCTV-Source'],
|
||||
'synthetic',
|
||||
);
|
||||
assert.equal(
|
||||
(
|
||||
await app.call(
|
||||
`/frame/${STILL.id}`,
|
||||
{ 'x-forwarded-for': '203.0.113.9' },
|
||||
first,
|
||||
)
|
||||
).headers['X-CCTV-Source'],
|
||||
'synthetic',
|
||||
);
|
||||
assert.deepEqual(
|
||||
[await frameSource(first), await frameSource(first), await frameSource(first)],
|
||||
[
|
||||
await frameSource(first),
|
||||
await frameSource(first),
|
||||
await frameSource(first),
|
||||
],
|
||||
['streetview', 'streetview', 'synthetic'],
|
||||
);
|
||||
assert.equal(streetViewCalls(), 2, 'no Google call over the budget');
|
||||
@@ -598,4 +619,13 @@ test('the Street View fallback spends a per-IP Google budget, and only with a ke
|
||||
'streetview',
|
||||
);
|
||||
assert.equal(streetViewCalls(), 3);
|
||||
|
||||
// Addresses within one IPv6 /64 share a budget.
|
||||
const v6 = (remoteAddress) => frameSource({ remoteAddress });
|
||||
assert.deepEqual(
|
||||
[await v6('2001:db8::1'), await v6('2001:db8::2'), await v6('2001:db8::3')],
|
||||
['streetview', 'streetview', 'synthetic'],
|
||||
);
|
||||
assert.equal(await v6('2001:db8:0:1::1'), 'streetview', 'another /64');
|
||||
assert.equal(streetViewCalls(), 6);
|
||||
});
|
||||
Reference in new issue
Block a user