File size: 1,890 Bytes
e5c2788
054d73a
 
 
 
 
 
 
 
 
 
bc45e54
 
 
 
 
054d73a
 
 
 
bc45e54
 
054d73a
bc45e54
 
 
 
 
 
054d73a
bc45e54
 
 
054d73a
bc45e54
 
 
 
 
054d73a
 
bc45e54
054d73a
 
 
 
 
 
 
 
 
bc45e54
 
 
 
054d73a
bc45e54
 
054d73a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Configuration management for ClassLens backend."""

from __future__ import annotations

import os
from pathlib import Path
from functools import lru_cache

from dotenv import load_dotenv
from pydantic import BaseModel

# Load .env file — try project root first, then chatkit/
_root = Path(__file__).parent.parent.parent.parent  # hf-classlens-deploy/
_chatkit = Path(__file__).parent.parent.parent       # chatkit/
load_dotenv(_root / ".env")
load_dotenv(_chatkit / ".env")  # overrides root if both exist


class Settings(BaseModel):
    """Application settings loaded from environment variables."""

    # OpenAI (single key for both vision parsing and report generation)
    openai_api_key: str = ""

    # JWT Auth
    jwt_secret_key: str = ""
    jwt_algorithm: str = "HS256"
    jwt_expire_minutes: int = 1440  # 24 hours

    # Database
    database_path: str = ""  # auto-resolved if empty

    # Encryption key for sensitive data
    encryption_key: str = ""

    # File upload
    upload_dir: str = ""  # auto-resolved if empty
    max_file_size_mb: int = 20

    # Frontend URL for redirects
    frontend_url: str = "http://localhost:3000"

    class Config:
        env_file = ".env"


@lru_cache
def get_settings() -> Settings:
    """Get cached settings instance."""
    return Settings(
        openai_api_key=os.getenv("OPENAI_API_KEY", ""),
        jwt_secret_key=os.getenv("JWT_SECRET_KEY", "classlens-dev-secret-change-in-prod"),
        jwt_algorithm=os.getenv("JWT_ALGORITHM", "HS256"),
        jwt_expire_minutes=int(os.getenv("JWT_EXPIRE_MINUTES", "1440")),
        database_path=os.getenv("DATABASE_PATH", ""),
        encryption_key=os.getenv("ENCRYPTION_KEY", ""),
        upload_dir=os.getenv("UPLOAD_DIR", ""),
        max_file_size_mb=int(os.getenv("MAX_FILE_SIZE_MB", "20")),
        frontend_url=os.getenv("FRONTEND_URL", "http://localhost:3000"),
    )