add client ip to signup webhook
deploy / build-and-deploy (push) Successful in 34s

This commit is contained in:
bytedream committed 2026-10-29 12:43:17 +01:00
1 parent c12ad5cc57
commit a6005753df
3 files changed
+17 -4

No files matched your search

+2 -2
View File
@@ -261,7 +261,7 @@ Das Webhook wir so oft gesendet, bis der angegebene Webhook Endpoint eine Respon
Alle Webhooks:
| Beschreibung | HTTP Header | Body |
| ------------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Ein neuer Nutzer hat sich registriert | <pre>x-webhook-action: signup</pre> | <pre>{<br>&nbsp;&nbsp;// Vorname des Nutzers<br>&nbsp;&nbsp;firstname: string,<br>&nbsp;&nbsp;// Nachname des Nutzers<br>&nbsp;&nbsp;lastname: string,<br>&nbsp;&nbsp;// Geburtstag des Nutzers im YYYY-MM-DD format<br>&nbsp;&nbsp;birthday: string,<br>&nbsp;&nbsp;// Telefonnummer des Nutzers. `null` wenn keine angegeben wurde<br>&nbsp;&nbsp;telephone: string \| null,<br>&nbsp;&nbsp;// Spielername des Nutzers<br>&nbsp;&nbsp;username: string,<br>&nbsp;&nbsp;// Minecraft-Edition des Nutzers<br>&nbsp;&nbsp;edition: 'java' \| 'bedrock'<br>&nbsp;&nbsp;//UUID des Nutzers. null wenn keine UUID ermittelt werden konnte<br>&nbsp;&nbsp;uuid: string \| null<br>}</pre> |
| ------------------------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Ein neuer Nutzer hat sich registriert | <pre>x-webhook-action: signup</pre> | <pre>{<br>&nbsp;&nbsp;// Vorname des Nutzers<br>&nbsp;&nbsp;firstname: string,<br>&nbsp;&nbsp;// Nachname des Nutzers<br>&nbsp;&nbsp;lastname: string,<br>&nbsp;&nbsp;// Geburtstag des Nutzers im YYYY-MM-DD format<br>&nbsp;&nbsp;birthday: string,<br>&nbsp;&nbsp;// Telefonnummer des Nutzers. `null` wenn keine angegeben wurde<br>&nbsp;&nbsp;telephone: string \| null,<br>&nbsp;&nbsp;// Spielername des Nutzers<br>&nbsp;&nbsp;username: string,<br>&nbsp;&nbsp;// Minecraft-Edition des Nutzers<br>&nbsp;&nbsp;edition: 'java' \| 'bedrock'<br>&nbsp;&nbsp;//UUID des Nutzers. null wenn keine UUID ermittelt werden konnte<br>&nbsp;&nbsp;uuid: string \| null,<br>&nbsp;&nbsp;// IP-Adresse des Besuchers<br>&nbsp;&nbsp;ip: string<br>}</pre> |
| Ein neuer Report wurde erstellt | <pre>x-webhook-action: report</pre> | <pre>{<br>&nbsp;&nbsp;// Username des Reporters. `null` wenn der Report vom System gemacht wurde<br>&nbsp;&nbsp;reporter: string \| null,<br>&nbsp;&nbsp;// Username des reporteten Spielers. `null` wenn Spieler unbekannt ist<br>&nbsp;&nbsp;reported: string \| null,<br>&nbsp;&nbsp;// Grund des Reports<br>&nbsp;&nbsp;reason: string<br>}</pre> |
| Ein neuer Strike wurde erstellt | <pre>x-webhook-action: strike</pre> | <pre>{<br>&nbsp;&nbsp;// UUID des Spielers, der gestriked wurde</br>&nbsp;&nbsp;uuid: string<br>}</pre> |
+14 -2
View File
@@ -5,6 +5,17 @@ import { getJavaUuid } from '@util/minecraft.ts';
import { getSetting, SettingKey } from '@util/settings.ts';
import { sendWebhook, WebhookAction } from '@util/webhook.ts';
function getClientIp(context: { request: Request; clientAddress: string }) {
const forwardedFor = context.request.headers.get('x-forwarded-for');
if (forwardedFor) {
const ip = forwardedFor.split(',')[0].trim();
if (ip) return ip;
}
return context.clientAddress;
}
export const signup = {
signup: defineAction({
input: z.object({
@@ -20,7 +31,7 @@ export const signup = {
edition: z.enum(['java', 'bedrock']),
hash: z.string().nullish()
}),
handler: async (input) => {
handler: async (input, context) => {
// check if hash given and if so, if it's valid and nobody has already used it
if (input.hash) {
const directSignup = await db.getDirectSignupByHash({ hash: input.hash });
@@ -85,7 +96,8 @@ export const signup = {
telephone: input.phone,
username: input.username,
edition: input.edition,
uuid: uuid
uuid: uuid,
ip: getClientIp(context)
});
}
})
+1
View File
@@ -17,6 +17,7 @@ export type WebhookActionType<T extends WebhookAction> = {
username: string;
edition: 'java' | 'bedrock';
uuid: string | null;
ip: string;
};
[WebhookAction.Report]: {
reporter: string | null;