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`;
|
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`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+20
-11
@@ -328,7 +328,8 @@ async function handleResponse(
|
|||||||
store: Store,
|
store: Store,
|
||||||
page: Page,
|
page: Page,
|
||||||
link: Link,
|
link: Link,
|
||||||
response?: Response | null
|
response?: Response | null,
|
||||||
|
recursionDepth = 0
|
||||||
) {
|
) {
|
||||||
if (!response) {
|
if (!response) {
|
||||||
logger.debug(Print.noResponse(link, store, true));
|
logger.debug(Print.noResponse(link, store, true));
|
||||||
@@ -341,16 +342,24 @@ async function handleResponse(
|
|||||||
logger.warn(Print.rateLimit(link, store, true));
|
logger.warn(Print.rateLimit(link, store, true));
|
||||||
} else if (statusCode === 503) {
|
} else if (statusCode === 503) {
|
||||||
if (await checkIsCloudflare(store, page, link)) {
|
if (await checkIsCloudflare(store, page, link)) {
|
||||||
const response: Response | null = await page.waitForNavigation({
|
if (recursionDepth > 4) {
|
||||||
waitUntil: 'networkidle0'
|
logger.warn(Print.recursionLimit(link, store, true));
|
||||||
});
|
} else {
|
||||||
statusCode = await handleResponse(
|
const response: Response | null = await page.waitForNavigation(
|
||||||
browser,
|
{
|
||||||
store,
|
waitUntil: 'networkidle0'
|
||||||
page,
|
}
|
||||||
link,
|
);
|
||||||
response
|
recursionDepth++;
|
||||||
);
|
statusCode = await handleResponse(
|
||||||
|
browser,
|
||||||
|
store,
|
||||||
|
page,
|
||||||
|
link,
|
||||||
|
response,
|
||||||
|
recursionDepth
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn(Print.badStatusCode(link, store, statusCode, true));
|
logger.warn(Print.badStatusCode(link, store, statusCode, true));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user