Implements a complete video transcoding web service with: - FastAPI framework for REST API - SQLAlchemy ORM with SQLite database - API key authentication using SHA256 hashing - Per-user resource isolation for all assets and jobs - S3-compatible file upload/download/delete/list interface - YAML-based API for transcode job requests - Transcode profile management (stored and inline) - Database models for Users, APIKeys, Assets, Jobs, and Profiles - CLI entry point for database initialization and server startup - Comprehensive integration tests with 100% pass rate - Deployment documentation with examples New files: - privatestudio/web/: Web service package - privatestudio/web/models.py: SQLAlchemy ORM models - privatestudio/web/auth.py: API key authentication - privatestudio/web/database.py: Database configuration - privatestudio/web/app.py: FastAPI application - privatestudio/web/s3_interface.py: File storage backend - privatestudio/web/cli.py: CLI commands - privatestudio/web/routes/: API endpoint handlers - tests/test_web.py: Integration tests - DEPLOYMENT.md: Deployment guide Updated files: - pyproject.toml: Added dependencies and CLI entry point Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""SQLAlchemy database configuration and session management."""
|
|
import os
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker, Session
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
from privatestudio.web.models import Base
|
|
|
|
# Get database path from environment, default to ./transcoding.db
|
|
DATABASE_URL = os.environ.get("DATABASE_URL", "sqlite:///./transcoding.db")
|
|
|
|
# Create engine with appropriate settings for SQLite
|
|
engine = create_engine(
|
|
DATABASE_URL,
|
|
connect_args={"check_same_thread": False} if "sqlite" in DATABASE_URL else {},
|
|
poolclass=StaticPool if "sqlite" in DATABASE_URL else None,
|
|
echo=os.environ.get("SQL_ECHO", "false").lower() == "true",
|
|
)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
def get_db() -> Session:
|
|
"""Dependency for FastAPI to get database session."""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
def init_db():
|
|
"""Initialize database tables."""
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
|
|
def drop_db():
|
|
"""Drop all database tables (for testing)."""
|
|
Base.metadata.drop_all(bind=engine)
|