(
_: IpcMainInvokeEvent,
url: string,
timeoutMs: number = 300000
)
| 525 | } |
| 526 | |
| 527 | export async function fetchFile( |
| 528 | _: IpcMainInvokeEvent, |
| 529 | url: string, |
| 530 | timeoutMs: number = 300000 |
| 531 | ): Promise<{ success: boolean; data?: ArrayBuffer; contentType?: string; error?: string; }> { |
| 532 | if (!isValidHttpsUrl(url)) { |
| 533 | return { success: false, error: "Refusing to fetch a non-HTTPS URL" }; |
| 534 | } |
| 535 | |
| 536 | const controller = new AbortController(); |
| 537 | const timeout = setTimeout(() => controller.abort(), timeoutMs); |
| 538 | try { |
| 539 | const response = await fetch(url, { signal: controller.signal }); |
| 540 | if (!response.ok) { |
| 541 | return { success: false, error: `Fetch failed: ${response.status} ${response.statusText}` }; |
| 542 | } |
| 543 | const data = await response.arrayBuffer(); |
| 544 | const contentType = response.headers.get("content-type") || ""; |
| 545 | return { success: true, data, contentType }; |
| 546 | } catch (e) { |
| 547 | return { success: false, error: e instanceof Error ? e.message : "Unknown error" }; |
| 548 | } finally { |
| 549 | clearTimeout(timeout); |
| 550 | } |
| 551 | } |
nothing calls this directly
no test coverage detected