(url: string, options: RequestInit = {}, timeout = 800)
| 31 | // Fetch contents of top 10 search results |
| 32 | export async function get10BlueLinksContents(sources: SearchResult[]): Promise<ContentResult[]> { |
| 33 | async function fetchWithTimeout(url: string, options: RequestInit = {}, timeout = 800): Promise<Response> { |
| 34 | try { |
| 35 | const controller = new AbortController(); |
| 36 | const timeoutId = setTimeout(() => controller.abort(), timeout); |
| 37 | const response = await fetch(url, { ...options, signal: controller.signal }); |
| 38 | clearTimeout(timeoutId); |
| 39 | return response; |
| 40 | } catch (error) { |
| 41 | if (error) { |
| 42 | console.log(`Skipping ${url}!`); |
| 43 | } |
| 44 | throw error; |
| 45 | } |
| 46 | } |
| 47 | function extractMainContent(html: string): string { |
| 48 | try { |
| 49 | const $ = cheerio.load(html); |
no outgoing calls
no test coverage detected