- Create FastAPI application with async I/O - Implement Redis session storage (fixes session loss on restart) - Add JWT authentication with refresh tokens - Add Microsoft SSO support via MSAL - Copy all processors from src/ (100% reused, no changes) - Create file upload/download endpoints - Create metadata update endpoints - Create template CRUD endpoints - Add SQLAlchemy async database models - Add Docker Compose configuration with Redis Solves critical issues: - Session management: Redis replaces in-memory dicts - Scalability: Async FastAPI + microservices architecture - File handling: Persistent storage with auto-cleanup Key files: - backend/app/main.py - FastAPI entry point - backend/app/core/redis_client.py - Session store - backend/app/core/auth.py - JWT authentication - backend/app/api/* - All REST endpoints - backend/app/processors/ - Reused from src/ Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""Configuration management for Oliver Metadata Tool."""
|
|
|
|
import os
|
|
import shutil
|
|
import logging
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class Config:
|
|
"""Configuration class for managing settings."""
|
|
|
|
# App Info
|
|
APP_NAME = "Oliver Metadata Tool"
|
|
APP_VERSION = "3.0.0"
|
|
APP_DESCRIPTION = "Universal metadata creation and management tool"
|
|
|
|
# Paths
|
|
PROJECT_ROOT = Path(__file__).parent.parent
|
|
OUTPUT_DIR = PROJECT_ROOT / 'output'
|
|
BACKUP_DIR = OUTPUT_DIR / 'backup'
|
|
REPORTS_DIR = OUTPUT_DIR / 'reports'
|
|
|
|
# External tool paths (optional)
|
|
TESSERACT_PATH = os.getenv('TESSERACT_PATH')
|
|
FFMPEG_PATH = os.getenv('FFMPEG_PATH')
|
|
|
|
# Processing Settings
|
|
PDF_MAX_PAGES = 3 # Maximum pages to extract from PDF
|
|
|
|
# OCR Settings - languages for Tesseract (CGA region support)
|
|
# eng=English, chi_sim=Chinese Simplified, chi_tra=Chinese Traditional,
|
|
# jpn=Japanese, kor=Korean
|
|
OCR_LANGUAGES = os.getenv('OCR_LANGUAGES', 'eng+chi_sim+chi_tra+jpn+kor')
|
|
|
|
# AI Settings (for CLI and Web AI mode)
|
|
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
|
|
AI_MODEL = os.getenv('AI_MODEL', 'gpt-4o-mini') # Better than gpt-3.5-turbo
|
|
MAX_TOKENS = int(os.getenv('MAX_TOKENS', '500'))
|
|
TEMPERATURE = float(os.getenv('TEMPERATURE', '0.5')) # 0.5 better for factual content
|
|
MAX_TEXT_LENGTH = int(os.getenv('MAX_TEXT_LENGTH', '4000'))
|
|
|
|
# API Rate Limiting & Retry (from open source analysis)
|
|
API_TIMEOUT = int(os.getenv('API_TIMEOUT', '30'))
|
|
API_MAX_RETRIES = int(os.getenv('API_MAX_RETRIES', '3'))
|
|
API_RETRY_DELAY = float(os.getenv('API_RETRY_DELAY', '1.0')) # exponential backoff multiplier
|
|
|
|
@classmethod
|
|
def ensure_directories(cls):
|
|
"""Ensure required directories exist."""
|
|
cls.OUTPUT_DIR.mkdir(exist_ok=True)
|
|
cls.BACKUP_DIR.mkdir(exist_ok=True)
|
|
cls.REPORTS_DIR.mkdir(exist_ok=True)
|
|
|
|
@classmethod
|
|
def check_exiftool(cls):
|
|
"""Check if ExifTool is installed."""
|
|
exiftool_path = shutil.which('exiftool')
|
|
if not exiftool_path:
|
|
logger.warning("⚠️ ExifTool not found. Install with: brew install exiftool (macOS) or apt-get install libimage-exiftool-perl (Linux)")
|
|
return False
|
|
logger.info(f"✓ ExifTool found at {exiftool_path}")
|
|
return True
|
|
|
|
# Ensure directories on import
|
|
Config.ensure_directories()
|