Spaces:
Running
Running
Download server/pageBotChecks.ts from Felladrin/MiniSearch: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/Felladrin/MiniSearch/resolve/main/server/pageBotChecks.ts
- Command line
-
hf download hf://spaces/Felladrin/MiniSearch/server/pageBotChecks.ts
-
curl -L -o pageBotChecks.ts https://huggingface.co/spaces/Felladrin/MiniSearch/resolve/main/server/pageBotChecks.ts
1.65 kB
| /** | |
| * Recognizing a bot wall, and the identities to ask it with. A wall is not | |
| * the page being gone: the statuses and markers below say a wall answered, | |
| * and the user agents below are the ones walls tend to let through. | |
| */ | |
| /** | |
| * Statuses a bot wall answers with, rather than statuses the page is really | |
| * gone for. 202 and 405 are AWS WAF's challenge and CAPTCHA; 401, 403 and | |
| * 429 are every other wall and rate limit. | |
| */ | |
| export const REFUSAL_STATUSES: ReadonlySet<number> = new Set([ | |
| 202, 401, 403, 405, 429, | |
| ]); | |
| /** | |
| * Bot checks that answer 200, so no status says they turned the read away: | |
| * Anubis and Akamai mark their challenge page instead. | |
| */ | |
| const BOT_CHECK_MARKERS = ['id="anubis_version"', 'id="sec-if-cpt-container"']; | |
| /** | |
| * User agents of the link previews of Slack and Facebook/X. A site that | |
| * blocks a search reader often still renders for these, because a blocked | |
| * link preview costs it the clicks its own links bring. | |
| */ | |
| export const LINK_PREVIEW_USER_AGENTS = [ | |
| "Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)", | |
| "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0", | |
| ] as const; | |
| export function hasBotCheckMarkers(html: string): boolean { | |
| return BOT_CHECK_MARKERS.some((marker) => html.includes(marker)); | |
| } | |
| /** | |
| * Whether a page carries scripts, which is what makes it solvable by the | |
| * offline challenge solver and what makes a textless page a check rather | |
| * than an empty page. | |
| */ | |
| export function isScripted(html: string): boolean { | |
| return /<script[\s/>]/i.test(html); | |
| } | |