add external users add api
deploy / build-and-deploy (push) Successful in 17s

This commit is contained in:
bytedream committed 2026-10-29 20:31:10 +01:00
1 parent 3fe7a12481
commit 0259aad7fd
2 files changed
+96 -4

No files matched your search

+48 -4
View File
@@ -153,6 +153,50 @@
</details> </details>
<details>
<summary><code>PUT</code> <code>/api/users</code> (Erstellt einen neuen Spieler)</summary>
##### Request Body
```
{
// Vorname des Spielers
"firstname": string,
// Nachname des Spielers
"lastname": string,
// Geburtstag im YYYY-MM-DD Format
"birthday": string,
// Telefonnummer des Spielers
"phone": string,
// Minecraft-Username
"username": string,
// Minecraft-UUID mit Bindestrichen
"uuid": string,
// Minecraft-Edition
"edition": "java" | "bedrock"
}
```
##### Response Codes
| http code | beschreibung |
| --------- | ------------------------------------------ |
| 201 | Der User wurde erstellt |
| 400 | Der Request Body ist falsch |
| 401 | Es wurde ein falsches API Secret angegeben |
| 409 | Username oder UUID existiert bereits |
##### Response Body
```
{
// ID des neuen Users
"id": number
}
```
</details>
<details> <details>
<summary><code>GET</code> <code>/api/users/{uuid}</code> (Status eines Spielers)</summary> <summary><code>GET</code> <code>/api/users/{uuid}</code> (Status eines Spielers)</summary>
@@ -260,8 +304,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'<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 Users<br>&nbsp;&nbsp;ip: string<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 Users<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 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> | | 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> |
+48
View File
@@ -0,0 +1,48 @@
import { z } from 'astro:schema';
import { db } from '@db/database.ts';
import { externalApi } from '../_api.ts';
export const PUT = externalApi({
auth: true,
input: z.object({
firstname: z.string().trim().min(1),
lastname: z.string().trim().min(1),
birthday: z.string().date(),
phone: z.string().trim(),
username: z.string().trim().min(1),
uuid: z.string().uuid(),
edition: z.enum(['java', 'bedrock'])
}),
handler: async ({ input }) => {
const existing = await db.existsUser({
username: input.username,
uuid: input.uuid
});
if (existing) {
return new Response(JSON.stringify({ error: 'User with this username or uuid already exists' }), {
status: 409,
headers: {
'Content-Type': 'application/json'
}
});
}
const user = await db.addUser({
firstname: input.firstname,
lastname: input.lastname,
birthday: input.birthday,
telephone: input.phone || null,
username: input.username,
edition: input.edition,
uuid: input.uuid
});
return new Response(JSON.stringify({ id: user.id }), {
status: 201,
headers: {
'Content-Type': 'application/json'
}
});
}
});