mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 02:57:34 +00:00
feat(lookup): add protection against infinite recursion for Cloudflare (#1505)
Fixes #1459 Fixes #1490
This commit is contained in:
@@ -212,6 +212,21 @@ export const Print = {
|
||||
}
|
||||
|
||||
return `✖ ${buildProductString(link, store)} :: RATE LIMIT EXCEEDED`;
|
||||
},
|
||||
recursionLimit(link: Link, store: Store, color?: boolean): string {
|
||||
if (color) {
|
||||
return (
|
||||
'✖ ' +
|
||||
buildProductString(link, store, true) +
|
||||
' :: ' +
|
||||
chalk.yellow('CLOUDFLARE RETRY LIMIT REACHED, ABORT')
|
||||
);
|
||||
}
|
||||
|
||||
return `✖ ${buildProductString(
|
||||
link,
|
||||
store
|
||||
)} :: CLOUDFLARE RETRY LIMIT REACHED, ABORT`;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+13
-4
@@ -328,7 +328,8 @@ async function handleResponse(
|
||||
store: Store,
|
||||
page: Page,
|
||||
link: Link,
|
||||
response?: Response | null
|
||||
response?: Response | null,
|
||||
recursionDepth = 0
|
||||
) {
|
||||
if (!response) {
|
||||
logger.debug(Print.noResponse(link, store, true));
|
||||
@@ -341,16 +342,24 @@ async function handleResponse(
|
||||
logger.warn(Print.rateLimit(link, store, true));
|
||||
} else if (statusCode === 503) {
|
||||
if (await checkIsCloudflare(store, page, link)) {
|
||||
const response: Response | null = await page.waitForNavigation({
|
||||
if (recursionDepth > 4) {
|
||||
logger.warn(Print.recursionLimit(link, store, true));
|
||||
} else {
|
||||
const response: Response | null = await page.waitForNavigation(
|
||||
{
|
||||
waitUntil: 'networkidle0'
|
||||
});
|
||||
}
|
||||
);
|
||||
recursionDepth++;
|
||||
statusCode = await handleResponse(
|
||||
browser,
|
||||
store,
|
||||
page,
|
||||
link,
|
||||
response
|
||||
response,
|
||||
recursionDepth
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logger.warn(Print.badStatusCode(link, store, statusCode, true));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user