( domain: string, )
| 179 | | { status: 'check_failed'; error: Error } |
| 180 | |
| 181 | export async function checkDomainBlocklist( |
| 182 | domain: string, |
| 183 | ): Promise<DomainCheckResult> { |
| 184 | if (DOMAIN_CHECK_CACHE.has(domain)) { |
| 185 | return { status: 'allowed' } |
| 186 | } |
| 187 | try { |
| 188 | const response = await axios.get( |
| 189 | buildNoumenaPlatformUrl( |
| 190 | `/api/web/domain_info?domain=${encodeURIComponent(domain)}`, |
| 191 | ), |
| 192 | { timeout: DOMAIN_CHECK_TIMEOUT_MS }, |
| 193 | ) |
| 194 | if (response.status === 200) { |
| 195 | if (response.data.can_fetch === true) { |
| 196 | DOMAIN_CHECK_CACHE.set(domain, true) |
| 197 | return { status: 'allowed' } |
| 198 | } |
| 199 | return { status: 'blocked' } |
| 200 | } |
| 201 | // Non-200 status but didn't throw |
| 202 | return { |
| 203 | status: 'check_failed', |
| 204 | error: new Error(`Domain check returned status ${response.status}`), |
| 205 | } |
| 206 | } catch (e) { |
| 207 | logError(e) |
| 208 | return { status: 'check_failed', error: e as Error } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Check if a redirect is safe to follow |
no test coverage detected