Karte (map.js):
- OSM Overpass API: Restaurants, Tierärzte, Parkplätze, Bänke, Wasserstellen
- Leaflet.markercluster für alle OSM-Layer
- Standort-Dot mit GPS-Genauigkeitskreis, Wake-Lock bei Aufzeichnung
- Community-Pins setzen/löschen, Meldungen, Crosshair-Placement
- Layer-Sichtbarkeit in localStorage (by_map_visible_v1)
Routen (routes.js + routen.py):
- Komoot-Stil: SVG-Track-Preview, Foto-Upload, Nearby-POIs im Detail-Modal
- Neue Felder: is_public, hunde_tauglichkeit, foto_urls
- Rate-Endpoint (POST /api/routes/{id}/rate)
- Foto-Upload (POST /api/routes/{id}/photo)
- Fix: json_extract $[-1] → $[#-1] (SQLite-kompatibler Pfad für letztes Element)
Backend (osm.py, database.py, scheduler.py):
- /api/osm/pois: OSM-Overpass-Cache mit Tile-Logik (14 Tage TTL)
- /api/osm/user-poi: Community-Marker CRUD
- /api/osm/report: Marker als ungültig melden
- Neue Tabellen: osm_pois, osm_tiles, user_map_pois, osm_reports
- Giftköder-Archiv-Job (täglich 03:00, soft-delete nach Ablauf)
- Giftköder-Archiv-Job als APScheduler-CronJob
UI: Orte-Menüpunkt entfernt (in Karte integriert), APP_VER auf 62
140 lines
5.3 KiB
Python
140 lines
5.3 KiB
Python
"""
|
|
BAN YARO — FastAPI Hauptanwendung
|
|
"""
|
|
|
|
import os
|
|
import logging
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import FileResponse, JSONResponse
|
|
from contextlib import asynccontextmanager
|
|
|
|
from database import init_db
|
|
import ki
|
|
import scheduler as sched
|
|
|
|
logging.basicConfig(
|
|
level = logging.INFO,
|
|
format = "%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# Startup / Shutdown
|
|
# ------------------------------------------------------------------
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
logger.info("Ban Yaro startet...")
|
|
init_db()
|
|
logger.info(f"KI-Modus: {ki.KI_MODE}")
|
|
sched.start()
|
|
yield
|
|
sched.stop()
|
|
logger.info("Ban Yaro beendet.")
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# App
|
|
# ------------------------------------------------------------------
|
|
app = FastAPI(
|
|
title = "Ban Yaro API",
|
|
version = "0.1.0",
|
|
lifespan = lifespan,
|
|
docs_url = "/api/docs" if os.getenv("ENV") != "production" else None,
|
|
redoc_url = None,
|
|
)
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# API-Router registrieren (werden nach und nach hinzugefügt)
|
|
# ------------------------------------------------------------------
|
|
from routes.auth import router as auth_router
|
|
from routes.dogs import router as dogs_router
|
|
from routes.diary import router as diary_router
|
|
from routes.health import router as health_router
|
|
from routes.poison import router as poison_router
|
|
from routes.push import router as push_router
|
|
from routes.ki import router as ki_router
|
|
from routes.tieraerzte import router as tieraerzte_router
|
|
from routes.places import router as places_router
|
|
from routes.routen import router as routen_router
|
|
from routes.walks import router as walks_router
|
|
from routes.events import router as events_router
|
|
from routes.sitting import router as sitting_router
|
|
from routes.osm import router as osm_router
|
|
|
|
app.include_router(auth_router, prefix="/api/auth", tags=["Auth"])
|
|
app.include_router(dogs_router, prefix="/api/dogs", tags=["Hunde"])
|
|
app.include_router(diary_router, prefix="/api/dogs", tags=["Tagebuch"])
|
|
app.include_router(health_router, prefix="/api/dogs", tags=["Gesundheit"])
|
|
app.include_router(poison_router, prefix="/api/poison", tags=["Giftköder"])
|
|
app.include_router(push_router, prefix="/api/push", tags=["Push"])
|
|
app.include_router(ki_router, prefix="/api/ki", tags=["KI"])
|
|
app.include_router(tieraerzte_router, prefix="/api/tieraerzte", tags=["Tierärzte"])
|
|
app.include_router(places_router, prefix="/api/places", tags=["Orte"])
|
|
app.include_router(routen_router, prefix="/api/routes", tags=["Routen"])
|
|
app.include_router(walks_router, prefix="/api/walks", tags=["Gassi-Treffen"])
|
|
app.include_router(events_router, prefix="/api/events", tags=["Events"])
|
|
app.include_router(sitting_router, prefix="/api/sitting", tags=["Sitting"])
|
|
app.include_router(osm_router, prefix="/api/osm", tags=["OSM"])
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# Fehlerbehandlung — einheitliches JSON-Format
|
|
# ------------------------------------------------------------------
|
|
@app.exception_handler(Exception)
|
|
async def global_exception_handler(request: Request, exc: Exception):
|
|
logger.error(f"Unbehandelter Fehler: {exc}", exc_info=True)
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"detail": "Interner Serverfehler."}
|
|
)
|
|
|
|
|
|
# ------------------------------------------------------------------
|
|
# Statische Dateien + SPA-Fallback
|
|
# ------------------------------------------------------------------
|
|
STATIC_DIR = os.path.join(os.path.dirname(__file__), "static")
|
|
|
|
app.mount("/css", StaticFiles(directory=f"{STATIC_DIR}/css"), name="css")
|
|
app.mount("/js", StaticFiles(directory=f"{STATIC_DIR}/js"), name="js")
|
|
app.mount("/icons", StaticFiles(directory=f"{STATIC_DIR}/icons"), name="icons")
|
|
|
|
# User-generierte Medien (Fotos aus Tagebuch, Giftköder-Alarm, etc.)
|
|
MEDIA_DIR = os.getenv("MEDIA_DIR", "/data/media")
|
|
os.makedirs(MEDIA_DIR, exist_ok=True)
|
|
app.mount("/media", StaticFiles(directory=MEDIA_DIR), name="media")
|
|
|
|
@app.get("/favicon.ico")
|
|
async def favicon():
|
|
return FileResponse(f"{STATIC_DIR}/icons/favicon.ico")
|
|
|
|
@app.get("/manifest.json")
|
|
async def manifest():
|
|
return FileResponse(f"{STATIC_DIR}/manifest.json")
|
|
|
|
@app.get("/sw.js")
|
|
async def service_worker():
|
|
return FileResponse(
|
|
f"{STATIC_DIR}/sw.js",
|
|
headers={"Cache-Control": "no-cache, no-store, must-revalidate"}
|
|
)
|
|
|
|
# Web Share Target
|
|
@app.post("/share")
|
|
async def share_target(request: Request):
|
|
# Empfängt geteilte Inhalte vom Handy (Fotos, Links, Text)
|
|
# Weiterleitung zur App mit den Daten
|
|
return FileResponse(
|
|
f"{STATIC_DIR}/index.html",
|
|
headers={"Cache-Control": "no-cache"}
|
|
)
|
|
|
|
# SPA Fallback — ALLE nicht-API-Routen gehen zur index.html
|
|
@app.get("/{full_path:path}")
|
|
async def spa_fallback(full_path: str):
|
|
return FileResponse(
|
|
f"{STATIC_DIR}/index.html",
|
|
headers={"Cache-Control": "no-cache"}
|
|
)
|