mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
fix(street-level): links keep the recipient's preferences; aim under the screen centre
Review fixes for gekh's #1113 round: - a link runs show_street_level with origin 'programmatic', so its source switch and layer are not saved as the recipient's preferences; - with no place named, the action looks under the screen centre (aim 'screen-centre', armed false), keeps the sky refusal and leaves a link's armed point alone; - an armed OPEN aimed at the sky opens nothing instead of the far link point; - an imagery-stage failure is spoken as an error, missing imagery as missing (street.nearestOutcome); the card says "the view centre" in the interface language; - every photo the action opens reveals its panel, and revealPanel scrolls the panel into view in the phone sheet; - embed: EXPAND survives embed's own clean view, the lifted photo hides in cockpit, recording and scene playback, and a failed photo step closes the earlier photo before the view flies; - links pasted into an open tab run their street-level step after the restore settles; a superseded start link does not; - Mapillary's nearest search gives up after 12 s, body included.
This commit is contained in:
1 parent
3f55077c2c
commit
451f3e41cf
22 files changed
+716
-64
No files matched your search
@@ -82,6 +82,12 @@ export const SEQUENCE_IMAGE_FIELDS =
|
||||
* the imagery filter then choose among the spot's photos, not a few of them.
|
||||
*/
|
||||
export const NEAREST_LIMIT = 100;
|
||||
/**
|
||||
* A nearest-image search that has not answered (headers and body) in this
|
||||
* long is given up: a link or a posted view waits on it, and so does every
|
||||
* view queued behind that one.
|
||||
*/
|
||||
export const NEAREST_TIMEOUT_MS = 12_000;
|
||||
/** Fields a nearest-image search needs: where each is, and the filter's. */
|
||||
export const NEAREST_IMAGE_FIELDS =
|
||||
'id,captured_at,geometry,computed_geometry,is_pano';
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
MAPILLARY_GRAPH_HOST,
|
||||
NEAREST_IMAGE_FIELDS,
|
||||
NEAREST_LIMIT,
|
||||
NEAREST_TIMEOUT_MS,
|
||||
SEQUENCE_IMAGE_FIELDS,
|
||||
SEQUENCE_IMAGES_LIMIT,
|
||||
} from './policy.js';
|
||||
@@ -69,7 +70,47 @@ export function createMapillarySource({
|
||||
...endpoints,
|
||||
};
|
||||
|
||||
async function graph(path, params = {}, { signal } = {}) {
|
||||
async function graph(path, params = {}, { signal, timeoutMs = 0 } = {}) {
|
||||
if (!timeoutMs) return graphOnce(path, params, { signal });
|
||||
// The whole answer, body included, within `timeoutMs`; the caller's
|
||||
// abort still wins.
|
||||
if (signal?.aborted) throw signal.reason;
|
||||
const controller = new AbortController();
|
||||
const onAbort = () => controller.abort(signal.reason);
|
||||
signal?.addEventListener('abort', onAbort, { once: true });
|
||||
const timer = setTimeout(
|
||||
() =>
|
||||
controller.abort(
|
||||
new MapillarySourceError('Mapillary did not answer in time', {
|
||||
status: 504,
|
||||
}),
|
||||
),
|
||||
timeoutMs,
|
||||
);
|
||||
try {
|
||||
// A body that never ends is given up too, whatever the fetch does.
|
||||
const gaveUp = new Promise((_, reject) =>
|
||||
controller.signal.addEventListener(
|
||||
'abort',
|
||||
() => reject(controller.signal.reason),
|
||||
{ once: true },
|
||||
),
|
||||
);
|
||||
return await Promise.race([
|
||||
graphOnce(path, params, { signal: controller.signal }),
|
||||
gaveUp,
|
||||
]);
|
||||
} catch (error) {
|
||||
if (signal?.aborted) throw signal.reason;
|
||||
if (controller.signal.aborted) throw controller.signal.reason;
|
||||
throw error;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
signal?.removeEventListener('abort', onAbort);
|
||||
}
|
||||
}
|
||||
|
||||
async function graphOnce(path, params, { signal }) {
|
||||
if (graphBase) {
|
||||
const search = new URLSearchParams(params);
|
||||
const response = await fetchImpl(`${graphBase}${path}?${search}`, {
|
||||
@@ -165,7 +206,7 @@ export function createMapillarySource({
|
||||
limit: String(Math.min(100, Math.max(1, limit))),
|
||||
fields: NEAREST_IMAGE_FIELDS,
|
||||
},
|
||||
{ signal },
|
||||
{ signal, timeoutMs: NEAREST_TIMEOUT_MS },
|
||||
);
|
||||
return Array.isArray(payload?.data) ? payload.data : [];
|
||||
},
|
||||
|
||||
@@ -179,3 +179,44 @@ test('Graph endpoint errors keep their status', async () => {
|
||||
(error) => error.status === 503 && error.keyRequired === true,
|
||||
);
|
||||
});
|
||||
|
||||
test('a nearest-image search that never answers is given up, body included', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const { NEAREST_TIMEOUT_MS } = await import('./policy.js');
|
||||
// Headers arrive; the body never ends, and the fetch ignores its signal.
|
||||
const { fetchImpl } = fakeFetch(() => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: () => new Promise(() => {}),
|
||||
}));
|
||||
const source = createMapillarySource({ token: 'MLY|1|abc', fetchImpl });
|
||||
const pending = source.nearestImages({ lat: 1, lon: 2 });
|
||||
const outcome = pending.then(
|
||||
() => 'answered',
|
||||
(error) => error,
|
||||
);
|
||||
await Promise.resolve();
|
||||
t.mock.timers.tick(NEAREST_TIMEOUT_MS);
|
||||
const error = await outcome;
|
||||
assert.ok(error instanceof MapillarySourceError, String(error));
|
||||
assert.equal(error.status, 504);
|
||||
assert.equal(error.keyRequired, false, 'not a key problem');
|
||||
});
|
||||
|
||||
test('the caller’s abort still ends a nearest-image search before its deadline', async () => {
|
||||
const { fetchImpl } = fakeFetch(
|
||||
(_url, init) =>
|
||||
new Promise((_, reject) =>
|
||||
init.signal.addEventListener('abort', () => reject(init.signal.reason)),
|
||||
),
|
||||
);
|
||||
const source = createMapillarySource({ token: 'MLY|1|abc', fetchImpl });
|
||||
const controller = new AbortController();
|
||||
const pending = source.nearestImages(
|
||||
{ lat: 1, lon: 2 },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
const reason = new Error('the turn moved on');
|
||||
controller.abort(reason);
|
||||
await assert.rejects(pending, (error) => error === reason);
|
||||
});
|
||||
Reference in new issue
Block a user