67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
"""Application configuration management."""
|
|
|
|
from functools import lru_cache
|
|
from typing import Literal
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings loaded from environment variables."""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
case_sensitive=False,
|
|
extra="ignore",
|
|
)
|
|
|
|
# Application
|
|
app_env: Literal["dev", "prod"] = "dev"
|
|
app_host: str = "0.0.0.0"
|
|
app_port: int = 8000
|
|
|
|
# Database
|
|
database_url: str = "sqlite+aiosqlite:///./app.db"
|
|
|
|
# S3 Storage
|
|
s3_endpoint_url: str | None = None
|
|
s3_region: str = "us-east-1"
|
|
s3_access_key_id: str
|
|
s3_secret_access_key: str
|
|
media_bucket: str = "itcloud-media"
|
|
trash_bucket: str = "itcloud-trash"
|
|
|
|
# Security
|
|
jwt_secret: str
|
|
jwt_algorithm: str = "HS256"
|
|
jwt_access_ttl_seconds: int = 900
|
|
jwt_refresh_ttl_seconds: int = 1209600
|
|
|
|
# Upload limits
|
|
max_upload_size_bytes: int = 3221225472 # 3GB
|
|
signed_url_ttl_seconds: int = 600
|
|
default_storage_quota_bytes: int = 3221225472 # 3GB per user
|
|
|
|
# CORS
|
|
cors_origins: str = "http://localhost:5173"
|
|
|
|
@property
|
|
def cors_origins_list(self) -> list[str]:
|
|
"""Parse CORS origins as a list."""
|
|
return [origin.strip() for origin in self.cors_origins.split(",")]
|
|
|
|
# Redis
|
|
redis_url: str = "redis://localhost:6379/0"
|
|
|
|
# Thumbnails
|
|
thumbnail_max_size: int = 1024
|
|
thumbnail_quality: int = 85
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
"""Get cached application settings."""
|
|
return Settings()
|