mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(street-level): review follow-ups — shares judged against the last draw; refused pictures stay refused
From the maintainer review of #1134 (approve with follow-ups): - lineCoverage: a share is judged against the cap the tile was last drawn with, not against later shares that redrew nothing, so small increases add up (a retained tile stayed at 100 points after its share grew to 116). A rebuild's measuring pass no longer counts as a draw. - photoViewer: a picture refused for its size (bytes, streamed bytes or decoded side) is marked `tooLarge`, and the viewer never loads that file again by any path; the flat fallback had retried an oversized SD file through an <img>, which has no size limit. - Regressions for both: cumulative share growth below the threshold, and a refused SD panorama that is not fetched again as a flat photo. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
de83e1c17f
commit
e3bc431f9a
5 files changed
+129
-16
No files matched your search
@@ -78,7 +78,7 @@ async function loadBitmap(url, timeoutMs, resize, failure, signal) {
|
||||
// Picture hosts are not ours: refuse a file or an image past any real
|
||||
// photo's size before it is decoded.
|
||||
const length = Number(response.headers?.get?.('content-length'));
|
||||
if (length > MAX_IMAGE_BYTES) throw new Error(failure);
|
||||
if (length > MAX_IMAGE_BYTES) throw oversized(failure);
|
||||
const blob = await boundedBlob(response, failure);
|
||||
const bitmap = await (resize
|
||||
? createImageBitmap(blob, {
|
||||
@@ -90,10 +90,12 @@ async function loadBitmap(url, timeoutMs, resize, failure, signal) {
|
||||
// (A resized decode reports its new size: this guards unresized ones.)
|
||||
if (bitmap.width > MAX_IMAGE_SIDE || bitmap.height > MAX_IMAGE_SIDE) {
|
||||
bitmap.close?.();
|
||||
throw new Error(failure);
|
||||
throw oversized(failure);
|
||||
}
|
||||
return bitmap;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// A size refusal stays one: the viewer must not fetch it another way.
|
||||
if (error?.tooLarge) throw error;
|
||||
throw new Error(failure);
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
@@ -101,6 +103,14 @@ async function loadBitmap(url, timeoutMs, resize, failure, signal) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A picture refused for its size (`tooLarge`): the viewer will not load
|
||||
* that file another way, an <img> having no size limit at all.
|
||||
*/
|
||||
export function oversized(failure) {
|
||||
return Object.assign(new Error(failure), { tooLarge: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* The body as a Blob, read with a running count so a host that sends no
|
||||
* length (or a false one) cannot fill memory before the cap is checked.
|
||||
@@ -109,7 +119,7 @@ async function boundedBlob(response, failure) {
|
||||
const reader = response.body?.getReader?.();
|
||||
if (!reader) {
|
||||
const blob = await response.blob();
|
||||
if (blob.size > MAX_IMAGE_BYTES) throw new Error(failure);
|
||||
if (blob.size > MAX_IMAGE_BYTES) throw oversized(failure);
|
||||
return blob;
|
||||
}
|
||||
const chunks = [];
|
||||
@@ -120,7 +130,7 @@ async function boundedBlob(response, failure) {
|
||||
total += value.byteLength;
|
||||
if (total > MAX_IMAGE_BYTES) {
|
||||
reader.cancel().catch(() => {});
|
||||
throw new Error(failure);
|
||||
throw oversized(failure);
|
||||
}
|
||||
chunks.push(value);
|
||||
}
|
||||
@@ -226,8 +236,17 @@ export function createPhotoViewer({
|
||||
/** ‹ › presses run one after another, each from where the last one went. */
|
||||
let steps = Promise.resolve();
|
||||
|
||||
const loadAs = (url, options) =>
|
||||
load(url, { failure: LOAD_FAILED, ...options });
|
||||
/** Files refused for their size: never loaded again, by any path. */
|
||||
const refused = new Set();
|
||||
async function loadAs(url, options) {
|
||||
if (refused.has(url)) throw oversized(LOAD_FAILED);
|
||||
try {
|
||||
return await load(url, { failure: LOAD_FAILED, ...options });
|
||||
} catch (error) {
|
||||
if (error?.tooLarge) refused.add(url);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function requestRender() {
|
||||
render?.governorRequestRender?.(`${providerId}-viewer`);
|
||||
@@ -796,6 +815,7 @@ export function createPhotoViewer({
|
||||
unmount() {
|
||||
openSeq++;
|
||||
dropSharpPanorama();
|
||||
refused.clear();
|
||||
openingId = null;
|
||||
keepViewFor = null;
|
||||
flatSharpUrl = null;
|
||||
|
||||
Reference in new issue
Block a user