initial commit
Some checks failed
deploy / build-and-deploy (push) Failing after 21s

This commit is contained in:
2025-05-18 13:16:20 +02:00
commit 60f3f8a096
148 changed files with 17900 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { z } from 'astro:schema';
import type { APIRoute } from 'astro';
import { API_SECRET } from 'astro:env/server';
import { db } from '@db/database.ts';
import { BASE_PATH } from 'astro:env/client';
const postSchema = z.object({
event: z.string(),
title: z.string(),
users: z.array(z.string())
});
export const POST: APIRoute = async ({ request }) => {
if (API_SECRET && request.headers.get('authorization') !== `Basic ${API_SECRET}`) {
return new Response(null, { status: 401 });
}
let parsed;
try {
parsed = await postSchema.parseAsync(await request.json());
} catch (_) {
return new Response(null, { status: 400 });
}
const feedbacks = await db.addUserFeedbacks({
event: parsed.event,
title: parsed.title,
uuids: parsed.users
});
const response = feedbacks.map((feedback) => ({
uuid: feedback.uuid,
url: `${BASE_PATH}/feedback/${feedback.urlHash}`
}));
return new Response(JSON.stringify({ feedback: response }), { status: 200 });
};

View File

@@ -0,0 +1,44 @@
import type { APIRoute } from 'astro';
import { API_SECRET } from 'astro:env/server';
import { z } from 'astro:schema';
import { db } from '@db/database.ts';
const postSchema = z.object({
user: z.string(),
killer: z.string().nullable(),
message: z.string()
});
export const POST: APIRoute = async ({ request }) => {
if (API_SECRET && request.headers.get('authorization') !== `Basic ${API_SECRET}`) {
return new Response(null, { status: 401 });
}
let parsed;
try {
parsed = await postSchema.parseAsync(await request.json());
} catch (_) {
return new Response(null, { status: 400 });
}
let users;
if (parsed.killer) {
users = await db.getUsersByUuid({ uuid: [parsed.user, parsed.killer] });
} else {
users = await db.getUsersByUuid({ uuid: [parsed.user] });
}
const user = users[parsed.user];
const killer = parsed.killer ? users[parsed.killer] : null;
if (!user || (!killer && parsed.killer)) {
return new Response(null, { status: 404 });
}
await db.addDeath({
message: parsed.message,
deadUserId: user.id,
killerUserId: killer?.id
});
return new Response(null, { status: 200 });
};

View File

@@ -0,0 +1,74 @@
import type { APIRoute } from 'astro';
import { db } from '@db/database.ts';
import { API_SECRET } from 'astro:env/server';
import { z } from 'astro:schema';
const postSchema = z.object({
user: z.string()
});
export const POST: APIRoute = async ({ request }) => {
if (API_SECRET && request.headers.get('authorization') !== `Basic ${API_SECRET}`) {
return new Response(null, { status: 401 });
}
let parsed;
try {
parsed = await postSchema.parseAsync(await request.json());
} catch (_) {
return new Response(null, { status: 400 });
}
const user = (await db.getUsersByUuid({ uuid: [parsed.user] }))[parsed.user];
if (user == null) {
return new Response(null, { status: 404 });
}
const team = await db.getTeamByUserUuid({ uuid: parsed.user });
if (team == null) {
return new Response(null, { status: 404 });
}
const death = await db.getDeathByUserId({ userId: user.id });
const strikes = await db.getStrikesByTeamId({ teamId: team.team.id });
const response = {
team: {
name: team.team.name,
color: team.team.color
},
dead: death != null,
strikeWeight: strikes.map((strike) => strike.reason.weight).reduce((a, b) => a + b, 0),
lastJoined: team.team.lastJoined ? new Date(team.team.lastJoined).getTime() : null
};
return new Response(JSON.stringify(response));
};
const putSchema = z.object({
user: z.string(),
lastJoined: z.number()
});
export const PUT: APIRoute = async ({ request }) => {
if (API_SECRET && request.headers.get('authorization') !== `Basic ${API_SECRET}`) {
return new Response(null, { status: 401 });
}
let parsed;
try {
parsed = await putSchema.parseAsync(await request.json());
} catch (_) {
return new Response(null, { status: 400 });
}
const team = await db.getTeamByUserUuid({ uuid: parsed.user });
if (team == null) {
return new Response(null, { status: 404 });
}
await db.editTeam({
id: team.team.id,
lastJoined: new Date(parsed.lastJoined).toISOString()
});
return new Response(null, { status: 200 });
};

View File

@@ -0,0 +1,26 @@
import type { APIRoute } from 'astro';
import { db } from '@db/database.ts';
import { API_SECRET } from 'astro:env/server';
export const GET: APIRoute = async ({ request }) => {
if (API_SECRET && request.headers.get('authorization') !== `Basic ${API_SECRET}`) {
return new Response(null, { status: 401 });
}
const teams = await db.getTeams({});
const response = [];
for (const team of teams) {
const users = [];
if (team.memberOne.uuid) users.push(team.memberOne.uuid);
if (team.memberTwo.uuid) users.push(team.memberTwo.uuid);
response.push({
name: team.name,
color: team.color,
users: users
});
}
return new Response(JSON.stringify(response));
};