From efe7a61e3bc45c89964c349422f27475c580abe7 Mon Sep 17 00:00:00 2001 From: "yanlong.wang" Date: Thu, 18 Jul 2024 12:33:19 +0800 Subject: [PATCH] fix: timeout parameter --- backend/functions/src/cloud-functions/crawler.ts | 4 ++-- backend/functions/src/dto/scrapping-options.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/functions/src/cloud-functions/crawler.ts b/backend/functions/src/cloud-functions/crawler.ts index cce75ff..68fea0c 100644 --- a/backend/functions/src/cloud-functions/crawler.ts +++ b/backend/functions/src/cloud-functions/crawler.ts @@ -710,7 +710,7 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`; const formatted = await this.formatSnapshot(crawlerOptions.respondWith, scrapped, urlToCrawl); chargeAmount = this.getChargeAmount(formatted); - if (crawlerOptions.timeout !== null) { + if (crawlerOptions.timeout === undefined) { return formatted; } } @@ -734,7 +734,7 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`; const formatted = await this.formatSnapshot(crawlerOptions.respondWith, scrapped, urlToCrawl); chargeAmount = this.getChargeAmount(formatted); - if (crawlerOptions.timeout !== null) { + if (crawlerOptions.timeout === undefined) { if (crawlerOptions.respondWith === 'screenshot' && Reflect.get(formatted, 'screenshotUrl')) { return assignTransferProtocolMeta(`${formatted}`, diff --git a/backend/functions/src/dto/scrapping-options.ts b/backend/functions/src/dto/scrapping-options.ts index 0eec389..43ea49e 100644 --- a/backend/functions/src/dto/scrapping-options.ts +++ b/backend/functions/src/dto/scrapping-options.ts @@ -213,8 +213,8 @@ export class CrawlerOptions extends AutoCastable { } let timeoutSeconds = parseInt(ctx?.req.get('x-timeout') || ''); - if (!isNaN(timeoutSeconds) && timeoutSeconds > 0 && timeoutSeconds <= 180) { - instance.timeout = timeoutSeconds; + if (!isNaN(timeoutSeconds) && timeoutSeconds > 0) { + instance.timeout = timeoutSeconds <= 180 ? timeoutSeconds : 180; } else if (ctx?.req.get('x-timeout')) { instance.timeout = null; }