pahvalentines/backend/app/main.py
michael 9c5b054dcc feat: Add Sonauto streaming audio on waiting page
Enable users to listen to their song while video generation continues
in the background. Backend proxies authenticated Sonauto stream API
since HTML audio elements cannot send auth headers.

- Add streaming_ready_at column to track when stream becomes available
- Enable streaming in Sonauto API request payload
- Handle GENERATING_STREAMING_READY webhook status
- Add /api/stream/{session_id} proxy endpoint using httpx
- Update StatusResponse with streaming_ready and task_id fields
- Add audio player UI with autoplay fallback for mobile
- Fade out audio gracefully before redirect to result page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 08:23:14 -06:00

67 lines
1.7 KiB
Python

"""FastAPI application entry point."""
import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import settings
from app.routers import health, results, stream, submissions, webhook
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)
# Create FastAPI app
app = FastAPI(
title="PAH Backend API",
description="Valentine's Day Pet Love Song Generator Backend",
version="1.0.0",
)
# CORS configuration
app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ORIGINS,
allow_credentials=True,
allow_methods=["GET", "POST"],
allow_headers=["*"],
)
# Include routers
app.include_router(submissions.router)
app.include_router(webhook.router)
app.include_router(results.router)
app.include_router(stream.router)
app.include_router(health.router)
@app.on_event("startup")
async def startup_event() -> None:
"""Run on application startup."""
logger.info("PAH Backend API starting up...")
# Ensure storage directories exist
settings.IMG_STORAGE.mkdir(parents=True, exist_ok=True)
settings.AUDIO_STORAGE.mkdir(parents=True, exist_ok=True)
settings.VIDEO_STORAGE.mkdir(parents=True, exist_ok=True)
logger.info("Storage directories verified")
@app.on_event("shutdown")
async def shutdown_event() -> None:
"""Run on application shutdown."""
logger.info("PAH Backend API shutting down...")
@app.get("/")
async def root() -> dict:
"""Root endpoint returning API info."""
return {
"name": "PAH Backend API",
"version": "1.0.0",
"status": "running",
}