feat: Initial commit - Task Reporter incident response system
Complete implementation of the production line incident response system (生產線異常即時反應系統) including: Backend (FastAPI): - User authentication with AD integration and session management - Chat room management (create, list, update, members, roles) - Real-time messaging via WebSocket (typing indicators, reactions) - File storage with MinIO (upload, download, image preview) Frontend (React + Vite): - Authentication flow with token management - Room list with filtering, search, and pagination - Real-time chat interface with WebSocket - File upload with drag-and-drop and image preview - Member management and room settings - Breadcrumb navigation - 53 unit tests (Vitest) Specifications: - authentication: AD auth, sessions, JWT tokens - chat-room: rooms, members, templates - realtime-messaging: WebSocket, messages, reactions - file-storage: MinIO integration, file management - frontend-core: React SPA structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1
app/core/__init__.py
Normal file
1
app/core/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Core application configuration and utilities"""
|
||||
43
app/core/config.py
Normal file
43
app/core/config.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Application configuration loaded from environment variables"""
|
||||
from pydantic_settings import BaseSettings
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings"""
|
||||
|
||||
# Database
|
||||
DATABASE_URL: str
|
||||
|
||||
# Security
|
||||
FERNET_KEY: str
|
||||
|
||||
# AD API
|
||||
AD_API_URL: str
|
||||
|
||||
# Session Settings
|
||||
SESSION_INACTIVITY_DAYS: int = 3
|
||||
TOKEN_REFRESH_THRESHOLD_MINUTES: int = 5
|
||||
MAX_REFRESH_ATTEMPTS: int = 3
|
||||
|
||||
# Server
|
||||
HOST: str = "0.0.0.0"
|
||||
PORT: int = 8000
|
||||
DEBUG: bool = True
|
||||
|
||||
# MinIO Object Storage
|
||||
MINIO_ENDPOINT: str = "localhost:9000"
|
||||
MINIO_ACCESS_KEY: str = "minioadmin"
|
||||
MINIO_SECRET_KEY: str = "minioadmin"
|
||||
MINIO_BUCKET: str = "task-reporter-files"
|
||||
MINIO_SECURE: bool = False # Use HTTPS
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def get_settings() -> Settings:
|
||||
"""Get cached settings instance"""
|
||||
return Settings()
|
||||
29
app/core/database.py
Normal file
29
app/core/database.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Database connection and session management"""
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from app.core.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
# Create engine
|
||||
engine = create_engine(
|
||||
settings.DATABASE_URL,
|
||||
connect_args={"check_same_thread": False} if "sqlite" in settings.DATABASE_URL else {},
|
||||
echo=settings.DEBUG,
|
||||
)
|
||||
|
||||
# Create session factory
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
# Base class for models
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
def get_db():
|
||||
"""FastAPI dependency to get database session"""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
83
app/core/minio_client.py
Normal file
83
app/core/minio_client.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""MinIO client singleton for object storage"""
|
||||
from minio import Minio
|
||||
from minio.error import S3Error
|
||||
from app.core.config import get_settings
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_minio_client = None
|
||||
|
||||
|
||||
def get_minio_client() -> Minio:
|
||||
"""
|
||||
Get or create MinIO client singleton
|
||||
|
||||
Returns:
|
||||
Minio client instance
|
||||
"""
|
||||
global _minio_client
|
||||
|
||||
if _minio_client is None:
|
||||
settings = get_settings()
|
||||
|
||||
_minio_client = Minio(
|
||||
settings.MINIO_ENDPOINT,
|
||||
access_key=settings.MINIO_ACCESS_KEY,
|
||||
secret_key=settings.MINIO_SECRET_KEY,
|
||||
secure=settings.MINIO_SECURE
|
||||
)
|
||||
|
||||
logger.info(f"MinIO client initialized: {settings.MINIO_ENDPOINT}")
|
||||
|
||||
return _minio_client
|
||||
|
||||
|
||||
def initialize_bucket():
|
||||
"""
|
||||
Initialize MinIO bucket if it doesn't exist
|
||||
|
||||
Returns:
|
||||
True if bucket exists or was created successfully
|
||||
"""
|
||||
settings = get_settings()
|
||||
client = get_minio_client()
|
||||
bucket_name = settings.MINIO_BUCKET
|
||||
|
||||
try:
|
||||
# Check if bucket exists
|
||||
if not client.bucket_exists(bucket_name):
|
||||
# Create bucket
|
||||
client.make_bucket(bucket_name)
|
||||
logger.info(f"MinIO bucket created: {bucket_name}")
|
||||
else:
|
||||
logger.info(f"MinIO bucket already exists: {bucket_name}")
|
||||
|
||||
return True
|
||||
|
||||
except S3Error as e:
|
||||
logger.error(f"Failed to initialize MinIO bucket '{bucket_name}': {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error initializing MinIO bucket: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def health_check() -> bool:
|
||||
"""
|
||||
Check if MinIO connection is healthy
|
||||
|
||||
Returns:
|
||||
True if connection is healthy, False otherwise
|
||||
"""
|
||||
settings = get_settings()
|
||||
|
||||
try:
|
||||
client = get_minio_client()
|
||||
# List buckets as a health check
|
||||
client.list_buckets()
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"MinIO health check failed: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user