fix: timeout parameter

This commit is contained in:
yanlong.wang 2024-07-18 12:33:19 +08:00
parent 61ff011c13
commit efe7a61e3b
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
2 changed files with 4 additions and 4 deletions

View File

@ -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}`,

View File

@ -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;
}