|
1 | 1 | import { readFile } from "node:fs/promises"; |
2 | 2 | import { glob } from "glob"; |
3 | 3 |
|
4 | | -// Add ignore list configuration |
5 | 4 | const IGNORED_URL_PREFIXES = new Set([ |
6 | 5 | "https://github.com/boundless-xyz", |
7 | | - "https://sepolia.etherscan.io", |
| 6 | + "https://etherscan.io", |
8 | 7 | "https://polygonscan.com", |
9 | 8 | "https://zkevm.polygonscan.com", |
10 | | - "https://basescan.org", |
11 | | - "https://sepolia.basescan.org", |
12 | | - "https://arbiscan.io", |
13 | | - "https://sepolia.arbiscan.io", |
14 | | - "https://snowtrace.io", |
15 | | - "https://testnet.snowtrace.io", |
| 9 | + "https://basescan.org", |
| 10 | + "https://arbiscan.io", |
| 11 | + "https://snowtrace.io", |
16 | 12 | "https://lineascan.build", |
17 | | - "https://sepolia.lineascan.build", |
18 | 13 | "https://crates.io", |
19 | 14 | "https://ethereum.org", |
20 | 15 | "https://staking.boundless.network", |
21 | 16 | "https://app.aragon.org", |
22 | | - "https://etherscan.io", |
23 | 17 | "https://docs.alchemy.com/" |
24 | 18 | ]); |
25 | 19 |
|
26 | 20 | async function checkRemoteUrl(url: string): Promise<boolean> { |
27 | | - // Check if URL starts with any of the ignored prefixes |
28 | | - if ([...IGNORED_URL_PREFIXES].some((prefix) => url.startsWith(prefix))) { |
29 | | - return true; |
| 21 | + try { |
| 22 | + const currentUrl = new URL(url); |
| 23 | + |
| 24 | + // Check if the URL's hostname matches or is a subdomain of any ignored prefix |
| 25 | + for (const prefix of IGNORED_URL_PREFIXES) { |
| 26 | + try { |
| 27 | + const ignoredUrl = new URL(prefix); |
| 28 | + |
| 29 | + // Check for an exact hostname match OR a subdomain match |
| 30 | + // e.g., "sepolia.etherscan.io" ends with ".etherscan.io" |
| 31 | + if ( |
| 32 | + currentUrl.hostname === ignoredUrl.hostname || |
| 33 | + currentUrl.hostname.endsWith(`.${ignoredUrl.hostname}`) |
| 34 | + ) { |
| 35 | + return true; // It's an ignored URL, so we return true immediately |
| 36 | + } |
| 37 | + } catch { |
| 38 | + // Handle cases where a prefix in the list isn't a full URL, |
| 39 | + // and just do a simple startsWith check as a fallback. |
| 40 | + if (url.startsWith(prefix)) { |
| 41 | + return true; |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + } catch { |
| 46 | + // If the url itself is invalid, we can't fetch it. |
| 47 | + return false; |
30 | 48 | } |
31 | 49 |
|
| 50 | + |
| 51 | + // If no match was found, try to fetch the URL |
32 | 52 | try { |
33 | 53 | const response = await fetch(url); |
34 | | - |
35 | 54 | return response.status >= 200 && response.status < 300; |
36 | 55 | } catch { |
37 | 56 | return false; |
|
0 commit comments