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
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from src.bot.core.utils import print_logo

# API Routes für Dashboard
from src.api.dashboard.routes import set_bot_instance, dashboard_main_router
from src.api.dashboard.routes import set_bot_instance, dashboard_main_router, router_public
from mx_handler import TranslationHandler

colorama_init(autoreset=True)
Expand Down Expand Up @@ -78,6 +78,7 @@

# Dashboard-Routes einbinden
app.include_router(dashboard_main_router)
app.include_router(router_public)

async def start_webserver():
"""Startet den FastAPI Webserver auf Port 8040"""
Expand Down
15 changes: 11 additions & 4 deletions src/api/dashboard/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import discord
from src.api.dashboard.auth_routes import get_current_user
from typing import List, Optional
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import time
# Falls du Schemas nutzt: from .schemas import ServerStatus, UserInfo

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

try:
# Berechne Uptime (in Sekunden seit dem letzten Ready-Event)
uptime_seconds = (discord.utils.utcnow() - bot_instance.start_time).total_seconds() if hasattr(bot_instance, 'start_time') else 0
# Berechne Uptime (Robust gegen Naive/Aware-Mix)
now = discord.utils.utcnow()
start = getattr(bot_instance, 'start_time', now)

# Sicherstellen, dass beide aware sind
if start.tzinfo is None:
start = start.replace(tzinfo=timezone.utc)

uptime_seconds = (now - start).total_seconds()
uptime_minutes, remainder = divmod(int(uptime_seconds), 60)
uptime_hours, uptime_minutes = divmod(uptime_minutes, 60)
uptime_days, uptime_hours = divmod(uptime_hours, 24)
Expand Down Expand Up @@ -383,5 +390,5 @@ async def get_mega_data(guild_id: int, user: dict = Depends(get_current_user)):
dashboard_main_router.include_router(auth_router)
dashboard_main_router.include_router(settings_router)
dashboard_main_router.include_router(user_router)
dashboard_main_router.include_router(router_public)
# dashboard_main_router.include_router(router_public) # Move to main.py for root access

3 changes: 2 additions & 1 deletion src/web/hooks/useStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const useStats = () => {
useEffect(() => {
const fetchStats = async () => {
try {
const response = await fetch("https://api.managerx-bot.de/v1/managerx/stats");
const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:8040";
const response = await fetch(`${baseUrl}/v1/managerx/stats`);
if (!response.ok) throw new Error("Offline");

const result = await response.json();
Expand Down
2 changes: 1 addition & 1 deletion src/web/pages/LeaderboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const LeaderboardPage = memo(function LeaderboardPage() {
const fetchLeaderboard = async () => {
try {
const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:8040";
const response = await fetch(`${baseUrl}/dashboard/v1/managerx/leaderboard`);
const response = await fetch(`${baseUrl}/v1/managerx/leaderboard`);
if (response.ok) {
const data = await response.json();
if (data.success) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/pages/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const Status = memo(function Status() {
useEffect(() => {
const fetchStatus = async () => {
try {
// Abfrage an die neue FastAPI-Route für echte Bot-Daten
const response = await fetch("https://api.managerx-bot.de/v1/managerx/stats");
const baseUrl = import.meta.env.VITE_API_URL || "http://localhost:8040";
const response = await fetch(`${baseUrl}/v1/managerx/stats`);
if (!response.ok) throw new Error("Offline");

const result = await response.json();
Expand Down
Loading