| 565 | return undefined; |
| 566 | } |
| 567 | async function sendWebhook( |
| 568 | webhookUrl: string, |
| 569 | payload: unknown, |
| 570 | partIndex: number, |
| 571 | totalParts: number, |
| 572 | ): Promise<void> { |
| 573 | const partLabel = `part ${partIndex}/${totalParts}`; |
| 574 | console.log(`Sending Discord webhook (${partLabel})...`); |
| 575 | const response = await fetch(webhookUrl, { |
| 576 | method: "POST", |
| 577 | headers: { |
| 578 | "Content-Type": "application/json", |
| 579 | }, |
| 580 | body: JSON.stringify(payload), |
| 581 | }); |
| 582 | |
| 583 | if (!response.ok) { |
| 584 | const errorText = await response.text(); |
| 585 | console.error( |
| 586 | `Discord webhook request failed (${partLabel}): ${response.status} ${response.statusText}`, |
| 587 | ); |
| 588 | if (errorText) { |
| 589 | console.error(`Response body: ${errorText}`); |
| 590 | } |
| 591 | throw new Error( |
| 592 | `Discord webhook request failed (${response.status} ${response.statusText})`, |
| 593 | ); |
| 594 | } |
| 595 | |
| 596 | console.log(`Discord webhook delivered (${partLabel}).`); |
| 597 | } |
| 598 | |
| 599 | async function main(): Promise<void> { |
| 600 | const exportData = loadExport(); |