This commit is contained in:
14
README.md
14
README.md
@@ -101,6 +101,8 @@
|
||||
}
|
||||
```
|
||||
|
||||
##### Response Codes
|
||||
|
||||
| http code | beschreibung |
|
||||
| --------- | ----------------------------------------------------------------- |
|
||||
| 200 | / |
|
||||
@@ -115,17 +117,19 @@
|
||||
</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
|
||||
|
||||
```
|
||||
{
|
||||
// UUID eines Spielers
|
||||
"user": string
|
||||
"uuid": string
|
||||
}
|
||||
```
|
||||
|
||||
##### Response Codes
|
||||
|
||||
| http code | beschreibung |
|
||||
| --------- | ------------------------------------------ |
|
||||
| 200 | / |
|
||||
@@ -162,7 +166,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> // Vorname des Nutzers<br> firstname: string,<br> // Nachname des Nutzers<br> lastname: string,<br> //Geburtstag des Nutzers im YYYY-MM-DD format<br> birthday: string,<br> // Telefonnummer des Nutzers. `null` wenn keine angegeben wurde<br> telephone: string \| null,<br> // Spielername des Nutzers<br> username: string,<br> // Minecraft-Edition des Nutzers<br> edition: 'java' \| 'bedrock'</pre> |
|
||||
| ------------------------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Ein neuer Nutzer hat sich registriert | <pre>x-webhook-action: signup</pre> | <pre>{<br> // Vorname des Nutzers<br> firstname: string,<br> // Nachname des Nutzers<br> lastname: string,<br> //Geburtstag des Nutzers im YYYY-MM-DD format<br> birthday: string,<br> // Telefonnummer des Nutzers. `null` wenn keine angegeben wurde<br> telephone: string \| null,<br> // Spielername des Nutzers<br> username: string,<br> // Minecraft-Edition des Nutzers<br> edition: 'java' \| 'bedrock'<br> //UUID des Nutzers. null wenn keine UUID ermittelt werden konnte<br> uuid: string \| null<br>}</pre> |
|
||||
| Ein neuer Report wurde erstellt | <pre>x-webhook-action: report</pre> | <pre>{<br> // Username des Reporters. `null` wenn der Report vom System gemacht wurde<br> reporter: string \| null,<br> // Username des reporteten Spielers. `null` wenn Spieler unbekannt ist<br> reported: string \| null,<br> // Grund des Reports<br> reason: string<br>}</pre> |
|
||||
| Ein neuer Strike wurde erstellt | <pre>x-webhook-action: strike</pre> | <pre>{<br> // UUID des Spielers, der gestriked wurde</br> user: string<br>}</pre> |
|
||||
| Ein neuer Strike wurde erstellt | <pre>x-webhook-action: strike</pre> | <pre>{<br> // UUID des Spielers, der gestriked wurde</br> uuid: string<br>}</pre> |
|
||||
|
||||
@@ -120,8 +120,8 @@ export const report = {
|
||||
}
|
||||
|
||||
sendWebhook(WebhookAction.Report, {
|
||||
reporter: report.reporter.username,
|
||||
reported: report.reported?.username ?? null,
|
||||
reporter: report.reporter.uuid,
|
||||
reported: report.reported?.uuid ?? null,
|
||||
reason: input.reason
|
||||
});
|
||||
},
|
||||
@@ -211,7 +211,7 @@ export const report = {
|
||||
|
||||
// send webhook in background
|
||||
sendWebhook(WebhookAction.Strike, {
|
||||
user: user!.uuid!
|
||||
uuid: user!.uuid!
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,8 @@ export const signup = {
|
||||
birthday: new Date(input.birthday).toISOString().slice(0, 10),
|
||||
telephone: input.phone,
|
||||
username: input.username,
|
||||
edition: input.edition
|
||||
edition: input.edition,
|
||||
uuid: uuid
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import { checkApiBasicAuth } from '@util/auth.ts';
|
||||
const postSchema = z.object({
|
||||
event: z.string(),
|
||||
title: z.string(),
|
||||
users: z.array(z.string())
|
||||
uuids: z.array(z.string())
|
||||
});
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
@@ -25,7 +25,7 @@ export const POST: APIRoute = async ({ request }) => {
|
||||
const feedbacks = await db.addUserFeedbacks({
|
||||
event: parsed.event,
|
||||
title: parsed.title,
|
||||
uuids: parsed.users
|
||||
uuids: parsed.uuids
|
||||
});
|
||||
|
||||
const response = feedbacks.map((feedback) => ({
|
||||
|
||||
@@ -3,23 +3,23 @@ import type { APIRoute } from 'astro';
|
||||
import { db } from '@db/database.ts';
|
||||
import { checkApiBasicAuth } from '@util/auth.ts';
|
||||
|
||||
const getSchema = z.object({
|
||||
user: z.string()
|
||||
const postSchema = z.object({
|
||||
uuid: z.string()
|
||||
});
|
||||
|
||||
export const GET: APIRoute = async ({ request }) => {
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
if (!checkApiBasicAuth(request.headers)) {
|
||||
return new Response(null, { status: 401 });
|
||||
}
|
||||
|
||||
let parsed;
|
||||
try {
|
||||
parsed = await getSchema.parseAsync(await request.json());
|
||||
parsed = await postSchema.parseAsync(await request.json());
|
||||
} catch (_) {
|
||||
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 });
|
||||
|
||||
const strikes = await db.getStrikesByUserId({ userId: user.id });
|
||||
|
||||
@@ -16,6 +16,7 @@ export type WebhookActionType<T extends WebhookAction> = {
|
||||
telephone: string | null;
|
||||
username: string;
|
||||
edition: 'java' | 'bedrock';
|
||||
uuid: string | null;
|
||||
};
|
||||
[WebhookAction.Report]: {
|
||||
reporter: string | null;
|
||||
@@ -23,7 +24,7 @@ export type WebhookActionType<T extends WebhookAction> = {
|
||||
reason: string;
|
||||
};
|
||||
[WebhookAction.Strike]: {
|
||||
user: string;
|
||||
uuid: string;
|
||||
};
|
||||
}[T];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user