Trust embedded Zillow photo sets without visible count

This commit is contained in:
2026-03-28 03:40:50 -05:00
parent 446d43cc78
commit ece8fc548f
5 changed files with 86 additions and 7 deletions

View File

@@ -58,11 +58,29 @@ export function extractZillowStructuredPhotoCandidatesFromNextDataScript(scriptT
return out;
}
export function shouldUseStructuredZillowPhotos(candidates, expectedPhotoCount) {
const DEFAULT_MINIMUM_TRUSTED_STRUCTURED_PHOTO_COUNT = 12;
export function shouldUseStructuredZillowPhotos(candidates, options = {}) {
const count = Array.isArray(candidates) ? candidates.length : 0;
if (!Number.isFinite(expectedPhotoCount) || expectedPhotoCount <= 0) {
return false;
const normalizedOptions =
typeof options === "number"
? { expectedPhotoCount: options }
: options && typeof options === "object"
? options
: {};
const expectedPhotoCount = Number(normalizedOptions.expectedPhotoCount || 0);
const fallbackPhotoCount = Number(normalizedOptions.fallbackPhotoCount || 0);
const minimumTrustCount = Number(
normalizedOptions.minimumTrustCount || DEFAULT_MINIMUM_TRUSTED_STRUCTURED_PHOTO_COUNT
);
if (Number.isFinite(expectedPhotoCount) && expectedPhotoCount > 0) {
return count >= expectedPhotoCount;
}
return count >= expectedPhotoCount;
if (Number.isFinite(fallbackPhotoCount) && fallbackPhotoCount > 0) {
return count >= fallbackPhotoCount;
}
return count >= minimumTrustCount;
}