update api
All checks were successful
deploy / build-and-deploy (push) Successful in 13s

This commit is contained in:
2025-10-15 13:40:31 +02:00
parent d3af1cedfd
commit 4fee3a721a
6 changed files with 25 additions and 19 deletions

View File

@@ -101,6 +101,8 @@
} }
``` ```
##### Response Codes
| http code | beschreibung | | http code | beschreibung |
| --------- | ----------------------------------------------------------------- | | --------- | ----------------------------------------------------------------- |
| 200 | / | | 200 | / |
@@ -115,17 +117,19 @@
</details> </details>
<details> <details>
<summary><code>GET</code> <code>/api/player</code> (Status eines Spielers)</summary> <summary><code>POST</code> <code>/api/player</code> (Status eines Spielers)</summary>
##### Request Body ##### Request Body
``` ```
{ {
// UUID eines Spielers // UUID eines Spielers
"user": string "uuid": string
} }
``` ```
##### Response Codes
| http code | beschreibung | | http code | beschreibung |
| --------- | ------------------------------------------ | | --------- | ------------------------------------------ |
| 200 | / | | 200 | / |
@@ -161,8 +165,8 @@ Das Webhook wir so oft gesendet, bis der angegebene Webhook Endpoint eine Respon
Alle Webhooks: Alle Webhooks:
| Beschreibung | HTTP Header | Body | | 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'</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>}</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 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;user: 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> |

View File

@@ -120,8 +120,8 @@ export const report = {
} }
sendWebhook(WebhookAction.Report, { sendWebhook(WebhookAction.Report, {
reporter: report.reporter.username, reporter: report.reporter.uuid,
reported: report.reported?.username ?? null, reported: report.reported?.uuid ?? null,
reason: input.reason reason: input.reason
}); });
}, },
@@ -211,7 +211,7 @@ export const report = {
// send webhook in background // send webhook in background
sendWebhook(WebhookAction.Strike, { sendWebhook(WebhookAction.Strike, {
user: user!.uuid! uuid: user!.uuid!
}); });
} }
} }

View File

@@ -73,7 +73,8 @@ export const signup = {
birthday: new Date(input.birthday).toISOString().slice(0, 10), birthday: new Date(input.birthday).toISOString().slice(0, 10),
telephone: input.phone, telephone: input.phone,
username: input.username, username: input.username,
edition: input.edition edition: input.edition,
uuid: uuid
}); });
} }
}) })

View File

@@ -7,7 +7,7 @@ import { checkApiBasicAuth } from '@util/auth.ts';
const postSchema = z.object({ const postSchema = z.object({
event: z.string(), event: z.string(),
title: z.string(), title: z.string(),
users: z.array(z.string()) uuids: z.array(z.string())
}); });
export const POST: APIRoute = async ({ request }) => { export const POST: APIRoute = async ({ request }) => {
@@ -25,7 +25,7 @@ export const POST: APIRoute = async ({ request }) => {
const feedbacks = await db.addUserFeedbacks({ const feedbacks = await db.addUserFeedbacks({
event: parsed.event, event: parsed.event,
title: parsed.title, title: parsed.title,
uuids: parsed.users uuids: parsed.uuids
}); });
const response = feedbacks.map((feedback) => ({ const response = feedbacks.map((feedback) => ({

View File

@@ -3,23 +3,23 @@ import type { APIRoute } from 'astro';
import { db } from '@db/database.ts'; import { db } from '@db/database.ts';
import { checkApiBasicAuth } from '@util/auth.ts'; import { checkApiBasicAuth } from '@util/auth.ts';
const getSchema = z.object({ const postSchema = z.object({
user: z.string() uuid: z.string()
}); });
export const GET: APIRoute = async ({ request }) => { export const POST: APIRoute = async ({ request }) => {
if (!checkApiBasicAuth(request.headers)) { if (!checkApiBasicAuth(request.headers)) {
return new Response(null, { status: 401 }); return new Response(null, { status: 401 });
} }
let parsed; let parsed;
try { try {
parsed = await getSchema.parseAsync(await request.json()); parsed = await postSchema.parseAsync(await request.json());
} catch (_) { } catch (_) {
return new Response(null, { status: 400 }); return new Response(null, { status: 400 });
} }
const user = await db.getUserByUuid({ uuid: parsed.user }); const user = await db.getUserByUuid({ uuid: parsed.uuid });
if (!user) return new Response(null, { status: 404 }); if (!user) return new Response(null, { status: 404 });
const strikes = await db.getStrikesByUserId({ userId: user.id }); const strikes = await db.getStrikesByUserId({ userId: user.id });

View File

@@ -16,6 +16,7 @@ export type WebhookActionType<T extends WebhookAction> = {
telephone: string | null; telephone: string | null;
username: string; username: string;
edition: 'java' | 'bedrock'; edition: 'java' | 'bedrock';
uuid: string | null;
}; };
[WebhookAction.Report]: { [WebhookAction.Report]: {
reporter: string | null; reporter: string | null;
@@ -23,7 +24,7 @@ export type WebhookActionType<T extends WebhookAction> = {
reason: string; reason: string;
}; };
[WebhookAction.Strike]: { [WebhookAction.Strike]: {
user: string; uuid: string;
}; };
}[T]; }[T];