(url: string, retries: number = 0)
| 274 | } |
| 275 | |
| 276 | export async function downloadFile(url: string, retries: number = 0) { |
| 277 | const MAX_RETRIES = 3 |
| 278 | try { |
| 279 | const response = await fetch(url) |
| 280 | if (!response.ok) { |
| 281 | throw new Error(`Failed to fetch image with status ${response.status}`) |
| 282 | } |
| 283 | const contentType = response.headers.get('content-type') ?? 'image/jpg' |
| 284 | const blob = Buffer.from(await response.arrayBuffer()) |
| 285 | return { contentType, blob } |
| 286 | } catch (e) { |
| 287 | if (retries > MAX_RETRIES) throw e |
| 288 | return downloadFile(url, retries + 1) |
| 289 | } |
| 290 | } |
no outgoing calls
no test coverage detected