fix: make property-assessor safer for whatsapp runs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { extractHarPhotos } from "../../web-automation/scripts/har-photos.js";
|
||||
import { extractZillowPhotos } from "../../web-automation/scripts/zillow-photos.js";
|
||||
import { withTimeout } from "./async-timeout.js";
|
||||
|
||||
export type PhotoSource = "zillow" | "har";
|
||||
|
||||
@@ -19,12 +20,33 @@ export interface PhotoReviewResolution {
|
||||
discoveredListingUrls: Array<{ label: string; url: string }>;
|
||||
}
|
||||
|
||||
interface PhotoReviewDeps {
|
||||
timeoutMs?: number;
|
||||
extractZillowPhotosFn?: typeof extractZillowPhotos;
|
||||
extractHarPhotosFn?: typeof extractHarPhotos;
|
||||
}
|
||||
|
||||
const DEFAULT_PHOTO_EXTRACTION_TIMEOUT_MS = Number(
|
||||
process.env.PROPERTY_ASSESSOR_PHOTO_TIMEOUT_MS || 25_000
|
||||
);
|
||||
|
||||
export async function extractPhotoData(
|
||||
source: PhotoSource,
|
||||
url: string
|
||||
url: string,
|
||||
deps: PhotoReviewDeps = {}
|
||||
): Promise<PhotoExtractionResult> {
|
||||
const timeoutMs = deps.timeoutMs ?? DEFAULT_PHOTO_EXTRACTION_TIMEOUT_MS;
|
||||
const extractZillowPhotosFn = deps.extractZillowPhotosFn || extractZillowPhotos;
|
||||
const extractHarPhotosFn = deps.extractHarPhotosFn || extractHarPhotos;
|
||||
|
||||
if (source === "zillow") {
|
||||
const payload = await extractZillowPhotos(url);
|
||||
const payload = await withTimeout(
|
||||
() => extractZillowPhotosFn(url),
|
||||
{
|
||||
operationName: "Zillow photo extraction",
|
||||
timeoutMs
|
||||
}
|
||||
);
|
||||
return {
|
||||
source,
|
||||
requestedUrl: String(payload.requestedUrl || url),
|
||||
@@ -37,7 +59,13 @@ export async function extractPhotoData(
|
||||
};
|
||||
}
|
||||
|
||||
const payload = await extractHarPhotos(url);
|
||||
const payload = await withTimeout(
|
||||
() => extractHarPhotosFn(url),
|
||||
{
|
||||
operationName: "HAR photo extraction",
|
||||
timeoutMs
|
||||
}
|
||||
);
|
||||
return {
|
||||
source,
|
||||
requestedUrl: String(payload.requestedUrl || url),
|
||||
|
||||
Reference in New Issue
Block a user