Skip to content

Commit a0871cd

Browse files
Merge pull request #193 from ManagerX-Development/dev-builds/2.0.0-dashboard
feat: Implement global leaderboard and status pages with supporting A…
2 parents 079b789 + 6f54cca commit a0871cd

5 files changed

Lines changed: 18 additions & 9 deletions

File tree

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from src.bot.core.utils import print_logo
4141

4242
# API Routes für Dashboard
43-
from src.api.dashboard.routes import set_bot_instance, dashboard_main_router
43+
from src.api.dashboard.routes import set_bot_instance, dashboard_main_router, router_public
4444
from mx_handler import TranslationHandler
4545

4646
colorama_init(autoreset=True)
@@ -78,6 +78,7 @@
7878

7979
# Dashboard-Routes einbinden
8080
app.include_router(dashboard_main_router)
81+
app.include_router(router_public)
8182

8283
async def start_webserver():
8384
"""Startet den FastAPI Webserver auf Port 8040"""

src/api/dashboard/routes.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import discord
55
from src.api.dashboard.auth_routes import get_current_user
66
from typing import List, Optional
7-
from datetime import datetime, timedelta
7+
from datetime import datetime, timedelta, timezone
88
import time
99
# Falls du Schemas nutzt: from .schemas import ServerStatus, UserInfo
1010

@@ -45,8 +45,15 @@ async def get_stats(request: Request):
4545
raise HTTPException(status_code=503, detail="Bot-Verbindung nicht verfügbar")
4646

4747
try:
48-
# Berechne Uptime (in Sekunden seit dem letzten Ready-Event)
49-
uptime_seconds = (discord.utils.utcnow() - bot_instance.start_time).total_seconds() if hasattr(bot_instance, 'start_time') else 0
48+
# Berechne Uptime (Robust gegen Naive/Aware-Mix)
49+
now = discord.utils.utcnow()
50+
start = getattr(bot_instance, 'start_time', now)
51+
52+
# Sicherstellen, dass beide aware sind
53+
if start.tzinfo is None:
54+
start = start.replace(tzinfo=timezone.utc)
55+
56+
uptime_seconds = (now - start).total_seconds()
5057
uptime_minutes, remainder = divmod(int(uptime_seconds), 60)
5158
uptime_hours, uptime_minutes = divmod(uptime_minutes, 60)
5259
uptime_days, uptime_hours = divmod(uptime_hours, 24)
@@ -383,5 +390,5 @@ async def get_mega_data(guild_id: int, user: dict = Depends(get_current_user)):
383390
dashboard_main_router.include_router(auth_router)
384391
dashboard_main_router.include_router(settings_router)
385392
dashboard_main_router.include_router(user_router)
386-
dashboard_main_router.include_router(router_public)
393+
# dashboard_main_router.include_router(router_public) # Move to main.py for root access
387394

src/web/hooks/useStats.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export const useStats = () => {
2828
useEffect(() => {
2929
const fetchStats = async () => {
3030
try {
31-
const response = await fetch("https://api.managerx-bot.de/v1/managerx/stats");
31+
const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:8040";
32+
const response = await fetch(`${baseUrl}/v1/managerx/stats`);
3233
if (!response.ok) throw new Error("Offline");
3334

3435
const result = await response.json();

src/web/pages/LeaderboardPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const LeaderboardPage = memo(function LeaderboardPage() {
2626
const fetchLeaderboard = async () => {
2727
try {
2828
const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:8040";
29-
const response = await fetch(`${baseUrl}/dashboard/v1/managerx/leaderboard`);
29+
const response = await fetch(`${baseUrl}/v1/managerx/leaderboard`);
3030
if (response.ok) {
3131
const data = await response.json();
3232
if (data.success) {

src/web/pages/Status.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const Status = memo(function Status() {
2424
useEffect(() => {
2525
const fetchStatus = async () => {
2626
try {
27-
// Abfrage an die neue FastAPI-Route für echte Bot-Daten
28-
const response = await fetch("https://api.managerx-bot.de/v1/managerx/stats");
27+
const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:8040";
28+
const response = await fetch(`${baseUrl}/v1/managerx/stats`);
2929
if (!response.ok) throw new Error("Offline");
3030

3131
const result = await response.json();

0 commit comments

Comments
 (0)