92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add parent directory to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
sys.path.insert(0, str(Path(__file__).parent)) # Add backend directory too
|
|
|
|
from backend.api.validation import router as validation_router
|
|
from backend.api.transcripts import router as transcripts_router
|
|
from backend.api.transcripts_stub import youtube_auth_router # Keep stub for YouTube auth
|
|
from backend.api.summarization import router as summarization_router
|
|
from backend.api.pipeline import router as pipeline_router
|
|
from backend.api.cache import router as cache_router
|
|
from backend.api.videos import router as videos_router
|
|
from backend.api.models import router as models_router
|
|
from backend.api.export import router as export_router
|
|
from backend.api.templates import router as templates_router
|
|
from backend.api.auth import router as auth_router
|
|
from backend.api.summaries import router as summaries_router
|
|
from backend.api.batch import router as batch_router
|
|
from core.database import engine, Base
|
|
from core.config import settings
|
|
|
|
# YouTube authentication is handled by the backend API auth router
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
|
|
app = FastAPI(
|
|
title="YouTube Summarizer API",
|
|
description="AI-powered YouTube video summarization service with user authentication",
|
|
version="3.1.0"
|
|
)
|
|
|
|
# Create database tables on startup
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
"""Initialize database and create tables."""
|
|
# Import all models to ensure they are registered
|
|
from backend.models import User, RefreshToken, APIKey, EmailVerificationToken, PasswordResetToken, Summary, ExportHistory
|
|
from backend.models.batch_job import BatchJob, BatchJobItem
|
|
from backend.core.database_registry import registry
|
|
|
|
# Create all tables using the registry
|
|
registry.create_all_tables(engine)
|
|
logging.info("Database tables created/verified using registry")
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000", "http://localhost:3001", "http://localhost:3002", "http://localhost:3003"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth_router) # Authentication routes first
|
|
# YouTube auth is handled by the backend auth router above
|
|
app.include_router(validation_router)
|
|
app.include_router(transcripts_router)
|
|
app.include_router(youtube_auth_router) # YouTube auth stub endpoints
|
|
app.include_router(summarization_router)
|
|
app.include_router(pipeline_router)
|
|
app.include_router(cache_router)
|
|
app.include_router(videos_router)
|
|
app.include_router(models_router)
|
|
app.include_router(export_router)
|
|
app.include_router(templates_router)
|
|
app.include_router(summaries_router) # Summary history management
|
|
app.include_router(batch_router) # Batch processing
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "YouTube Summarizer API", "version": "1.0.0"}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "healthy"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) |