Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/stats-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Mini-Doku für die API-Endpunkte, die das Frontend unter `/statistiken` nutzt.
- `/api/metrics` (Kategorien/Definitionen)
- `/api/leaderboard?metric=...&limit=...&cursor=...` (Ranglisten mit Cursor-Paging)
- `/api/leaderboards?limit=...` (Top-Listen je Metrik)
- `/api/world-state` (globaler Weltzustand, aktuell Weltalter)
- `/api/players?q=...&limit=...` (Autocomplete)
- `/api/player?uuid=...` (Spieler-Detail)
- `/api/ban-status?query=...` (Bann-Status per exaktem Name oder UUID)
Expand Down Expand Up @@ -81,6 +82,7 @@ Edge-Cache (`caches.default`) + `Cache-Control`:

- `metrics`: `max-age=3600`
- `summary`: `max-age=60`
- `world-state`: `max-age=60`
- `leaderboard` / `leaderboards`: `max-age=60`
- `players`: `max-age=30`
- `player`: `max-age=60`
Expand All @@ -98,6 +100,40 @@ Mojang (`cape` / `profile`):
- Stale bei Upstream-Fehler: `30s`
- Header zusätzlich: `stale-while-revalidate=30`, `stale-if-error=86400`

## Weltzustand

`GET /api/world-state`

Liefert den globalen Zustand des aktiven Import-Snapshots. Aktuell nutzt der
Endpunkt die View `v_world_state` und gibt das vorberechnete Weltalter aus.
Das Frontend soll `world.ageDays` direkt anzeigen und keine eigene Umrechnung
von Ticks in Minecraft-Tage vornehmen.

Antwort:

```json
{
"world": {
"name": "world",
"ageTicks": 123456789,
"ageDays": 5144,
"importedAt": "2026-05-09T12:34:56+02:00"
},
"__generated": "2026-05-09T12:34:56+02:00",
"__generated_timezone": "Europe/Berlin"
}
```

Felder:

- `world.name`: Name der Minecraft-Welt, z. B. `world`
- `world.ageTicks`: Rohwert aus Bukkit/Paper `World#getFullTime()`
- `world.ageDays`: fertig berechnete Minecraft-Tage aus der Datenbank
- `world.importedAt`: Import-Zeitpunkt des Weltzustands

Wenn kein Weltzustand im aktiven Snapshot vorhanden ist, wird `world: null`
zurueckgegeben.

## Lokale Entwicklung

- `npm run dev` für Astro + Cloudflare-Worker-Runtime
Expand Down
8 changes: 8 additions & 0 deletions src/features/stats/StatsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export default function StatsApp() {
generatedIso,
setGeneratedIso,
totals,
worldState,
worldStateLoaded,
worldStateLoading,
worldStateError,
summaryLoaded,
summaryLoading,
summaryError,
Expand Down Expand Up @@ -457,6 +461,10 @@ export default function StatsApp() {
onOpenRankings={handleOpenRankingsFromOverview}
navigationDisabled={tabsDisabled}
totals={totals}
worldState={worldState}
worldStateLoaded={worldStateLoaded}
worldStateLoading={worldStateLoading}
worldStateError={worldStateError}
summaryLoaded={summaryLoaded}
summaryLoading={summaryLoading}
summaryError={summaryError}
Expand Down
5 changes: 5 additions & 0 deletions src/features/stats/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
MetricsResponse,
PlayersSearchResponse,
SummaryResponse,
WorldStateResponse,
} from './types';
import { fetchJsonOrThrow } from '../../lib/http/fetchJson';
import { toApiUrl } from '../../lib/http/apiUrl';
Expand All @@ -21,6 +22,10 @@ export function getSummary(metrics: string[], signal?: AbortSignal) {
);
}

export function getWorldState(signal?: AbortSignal) {
return fetchJsonOrThrow<WorldStateResponse>(toApiUrl('/api/world-state'), { signal });
}

export function getLeaderboard(
metricId: string,
limit: number,
Expand Down
14 changes: 13 additions & 1 deletion src/features/stats/components/sections/OverviewSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ async function mountOverview(overrides: OverviewOverrides = {}) {
hours: 123,
distance: 456,
mob_kills: 789,
creeper: 321,
},
worldState: {
name: 'world',
ageTicks: 102_880_000,
ageDays: 5_144,
importedAt: '2026-02-19T12:00:00.000Z',
},
worldStateLoaded: true,
worldStateLoading: false,
worldStateError: null,
summaryLoaded: true,
summaryLoading: false,
summaryError: null,
Expand Down Expand Up @@ -71,6 +79,10 @@ describe('OverviewSection', () => {
const onOpenRankings = vi.fn();
const view = await mountOverview({ onOpenRankings });

expect(view.container.textContent).toContain('Weltalter');
expect(view.container.textContent).toContain('5.144');
expect(view.container.textContent).toContain('Minecraft-Tage seit Weltstart.');

const leadCard = view.container.querySelector(
'[aria-label="Spielzeit Rangliste \u00f6ffnen"]',
) as HTMLElement | null;
Expand Down
Loading