pahvalentines/backend/app/main.py
michael c41e559e81 feat: migrate file storage from local filesystem to Google Cloud Storage
- Add google-cloud-storage dependency to requirements.txt
- Add GCS configuration settings to config.py
- Create storage.py utility module with upload/download/delete operations
  and temp file context managers for video generation
- Update submissions.py to upload photos to GCS and return full GCS URLs
- Update results.py to return full GCS URLs for video and record image
- Update workers.py to use GCS for audio download, video creation, and cleanup
- Update result.js to use audio_url directly from API response
- Update docker-compose.yml with GCS credentials mount

Storage now uses GCS bucket vday2026 in project holiday-project-india.
Database stores blob paths; URLs constructed at API response time.

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

71 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, image_safety, profanity, results, 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(health.router)
app.include_router(profanity.router)
app.include_router(image_safety.router)
@app.on_event("startup")
async def startup_event() -> None:
"""Run on application startup."""
logger.info("PAH Backend API starting up...")
# Verify GCS connectivity
try:
from app.services import storage
storage.check_connectivity()
logger.info("GCS storage verified")
except Exception as e:
logger.error(f"GCS connectivity check failed: {e}")
raise
@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",
}