mirror of
https://github.com/rommapp/romm.git
synced 2026-02-19 07:50:57 +01:00
According to multiple FastAPI discussions [1], FastAPI only includes a built-in mechanism to redirect requests including a trailing slash, to its variation without slash, using a `307` status code. This can be an issue when certain clients do not send the same headers on the redirected request. This change adds a custom FastAPI `APIRouter`, that registers both route path variations (with and without trailing slash), while only marking the path without slash for being included in the OpenAPI schema. [1] https://github.com/fastapi/fastapi/discussions/7298
24 lines
684 B
Python
24 lines
684 B
Python
from endpoints.responses.stats import StatsReturn
|
|
from handler.database import db_stats_handler
|
|
from utils.router import APIRouter
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/stats")
|
|
def stats() -> StatsReturn:
|
|
"""Endpoint to return the current RomM stats
|
|
|
|
Returns:
|
|
dict: Dictionary with all the stats
|
|
"""
|
|
|
|
return {
|
|
"PLATFORMS": db_stats_handler.get_platforms_count(),
|
|
"ROMS": db_stats_handler.get_roms_count(),
|
|
"SAVES": db_stats_handler.get_saves_count(),
|
|
"STATES": db_stats_handler.get_states_count(),
|
|
"SCREENSHOTS": db_stats_handler.get_screenshots_count(),
|
|
"FILESIZE": db_stats_handler.get_total_filesize(),
|
|
}
|