1 | type DiscordWebhook = { |
2 | webhook_url: string; |
3 | }; |
4 | type Base64 = string |
5 | export async function main( |
6 | discord_webhook: DiscordWebhook, |
7 | screenshot: Base64, |
8 | kind: 'pdf' | 'png', |
9 | app_path: string |
10 | ) { |
11 | const formData = new FormData(); |
12 | formData.append( |
13 | "files[0]", |
14 | new Blob([Buffer.from(screenshot, "base64")], { |
15 | type: kind === "pdf" ? "application/pdf" : "image/png", |
16 | }), |
17 | "report." + kind |
18 | ); |
19 | const fullAppPath = Bun.env["WM_BASE_URL"] + '/apps/get/' + app_path + '?workspace=' + Bun.env["WM_WORKSPACE"] |
20 | formData.append( |
21 | "payload_json", |
22 | JSON.stringify({ content: "App report of [" + app_path + "](" + fullAppPath + ")" }) |
23 | ); |
24 | const response = await fetch(discord_webhook.webhook_url, { |
25 | method: "POST", |
26 | body: formData, |
27 | }); |
28 | return response.text(); |
29 | } |