rewrite website

This commit is contained in:
2025-10-13 17:22:49 +02:00
parent a6d910f56a
commit 32f28e5324
263 changed files with 17904 additions and 14451 deletions

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

@@ -0,0 +1,48 @@
import { sleepSeconds } from './sleep.ts';
import { WEBHOOK_ENDPOINT } from 'astro:env/server';
export enum WebhookAction {
Signup = 'signup',
Report = 'report',
Strike = 'strike'
}
export type WebhookActionType<T extends WebhookAction> = {
[WebhookAction.Signup]: {
firstname: string;
lastname: string;
birthday: string;
telephone: string | null;
username: string;
edition: 'java' | 'bedrock';
};
[WebhookAction.Report]: {
reporter: string | null;
reported: string | null;
reason: string;
};
[WebhookAction.Strike]: {
user: string;
};
}[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, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-webhook-action': action
},
body: JSON.stringify(data)
});
if (response.status === 200) return;
} catch (_) {}
await sleepSeconds(60);
}
}