( url: string, abortController: AbortController, )
| 365 | } |
| 366 | |
| 367 | export async function getURLMarkdownContent( |
| 368 | url: string, |
| 369 | abortController: AbortController, |
| 370 | ): Promise<FetchedContent | RedirectInfo> { |
| 371 | if (!validateURL(url)) { |
| 372 | throw new Error('Invalid URL') |
| 373 | } |
| 374 | |
| 375 | // Check cache (LRUCache handles TTL automatically) |
| 376 | const cachedEntry = URL_CACHE.get(url) |
| 377 | if (cachedEntry) { |
| 378 | return { |
| 379 | bytes: cachedEntry.bytes, |
| 380 | code: cachedEntry.code, |
| 381 | codeText: cachedEntry.codeText, |
| 382 | content: cachedEntry.content, |
| 383 | contentType: cachedEntry.contentType, |
| 384 | finalUrl: cachedEntry.finalUrl, |
| 385 | persistedPath: cachedEntry.persistedPath, |
| 386 | persistedSize: cachedEntry.persistedSize, |
| 387 | redirectChain: cachedEntry.redirectChain, |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | let parsedUrl: URL |
| 392 | let upgradedUrl = url |
| 393 | |
| 394 | try { |
| 395 | parsedUrl = new URL(url) |
| 396 | |
| 397 | // Upgrade http to https if needed |
| 398 | if (parsedUrl.protocol === 'http:') { |
| 399 | parsedUrl.protocol = 'https:' |
| 400 | upgradedUrl = parsedUrl.toString() |
| 401 | } |
| 402 | |
| 403 | const hostname = parsedUrl.hostname |
| 404 | |
| 405 | // Check if the user has opted to skip the blocklist check |
| 406 | // This is for enterprise customers with restrictive security policies |
| 407 | // that prevent outbound connections to the remote session backend. |
| 408 | const settings = getSettings_DEPRECATED() |
| 409 | if (!settings.skipWebFetchPreflight) { |
| 410 | const checkResult = await checkDomainBlocklist(hostname) |
| 411 | switch (checkResult.status) { |
| 412 | case 'allowed': |
| 413 | // Continue with the fetch |
| 414 | break |
| 415 | case 'blocked': |
| 416 | throw new DomainBlockedError(hostname) |
| 417 | case 'check_failed': |
| 418 | throw new DomainCheckFailedError(hostname) |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if ( |
| 423 | process.env.NCODE_BUILD_MODE === 'noumena' || |
| 424 | process.env.USER_TYPE === 'noumena' |
no test coverage detected