initial commit
Some checks failed
deploy / build-and-deploy (push) Failing after 21s

This commit is contained in:
2025-05-18 13:16:20 +02:00
commit 60f3f8a096
148 changed files with 17900 additions and 0 deletions

33
src/util/webhook.ts Normal file
View File

@@ -0,0 +1,33 @@
import { sleepSeconds } from './sleep.ts';
import { WEBHOOK_ENDPOINT } from 'astro:env/client';
export enum WebhookAction {
Strike = 'strike'
}
export type WebhookActionType<T extends WebhookAction> = {
[WebhookAction.Strike]: {
users: string[];
totalWeight: number;
};
}[T];
export async function sendWebhook<T extends WebhookAction>(action: T, data: WebhookActionType<T>) {
if (!WEBHOOK_ENDPOINT || !/^https?:\/\/.+$/.test(WEBHOOK_ENDPOINT)) return;
while (true) {
try {
const response = await fetch(WEBHOOK_ENDPOINT, {
body: JSON.stringify(data),
headers: {
'x-webhook-action': action
},
keepalive: false
});
if (response.status === 200) return;
} catch (_) {}
await sleepSeconds(60);
}
}