48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# packetserver/http/server.py
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.templating import Jinja2Templates
|
|
from pathlib import Path
|
|
|
|
from .routers import public, profile, messages, send, bulletins
|
|
from packetserver.http.routers.bulletins import html_router
|
|
|
|
BASE_DIR = Path(__file__).parent.resolve()
|
|
|
|
app = FastAPI(
|
|
title="PacketServer HTTP API",
|
|
description="RESTful interface to the AX.25 packet radio BBS",
|
|
version="0.1.0",
|
|
)
|
|
|
|
# Define templates EARLY (before importing dashboard)
|
|
templates = Jinja2Templates(directory=BASE_DIR / "templates")
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
def timestamp_to_date(ts):
|
|
if ts is None:
|
|
return "Never"
|
|
try:
|
|
dt = datetime.fromtimestamp(float(ts), tz=timezone.utc)
|
|
return dt.strftime("%Y-%m-%d %H:%M:%S UTC")
|
|
except (ValueError, TypeError):
|
|
return "Invalid"
|
|
|
|
# Register the filter correctly
|
|
templates.env.filters["timestamp_to_date"] = timestamp_to_date
|
|
|
|
# Static files
|
|
app.mount("/static", StaticFiles(directory=BASE_DIR / "static"), name="static")
|
|
|
|
# Now safe to import dashboard (it needs templates)
|
|
from .routers import dashboard # add this line
|
|
|
|
# Include routers
|
|
app.include_router(public.router)
|
|
app.include_router(profile.router)
|
|
app.include_router(messages.router)
|
|
app.include_router(send.router)
|
|
app.include_router(dashboard.router)
|
|
app.include_router(bulletins.router)
|
|
app.include_router(html_router) |