File size: 1,787 Bytes
ec94fc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Application configuration via environment variables."""

import os
from functools import lru_cache
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """All config comes from environment variables or .env file."""

    # App
    app_name: str = "ISP Handbook Service"
    app_version: str = "1.0.0"
    debug: bool = False
    port: int = 7860  # Hugging Face Spaces default

    # External API endpoints (the source-of-truth JSON APIs)
    handbook_general_endpoint: str = ""
    university_handbook_endpoint: str = ""
    api_base_url: str = "https://finsapdev.qhtestingserver.com"
    general_sections_path: str = "/MODEL_APIS/handbook_general_sections.php"
    university_sections_path: str = "/MODEL_APIS/university_handbook.php"

    # Images
    images_dir: str = "./images"

    # Fonts
    font_dir: str = "./fonts"

    # CORS
    cors_origins: str = "http://localhost:5173,http://127.0.0.1:5173,https://finsapdev.qhtestingserver.com"

    # Request timeouts
    http_timeout: int = 25

    model_config = {"env_file": ".env", "env_file_encoding": "utf-8", "extra": "ignore"}

    @property
    def cors_origins_list(self) -> list[str]:
        return [o.strip() for o in self.cors_origins.split(",") if o.strip()]

    @property
    def general_endpoint_url(self) -> str:
        if self.handbook_general_endpoint:
            return self.handbook_general_endpoint
        return self.api_base_url.rstrip("/") + self.general_sections_path

    @property
    def university_endpoint_url(self) -> str:
        if self.university_handbook_endpoint:
            return self.university_handbook_endpoint
        return self.api_base_url.rstrip("/") + self.university_sections_path


@lru_cache()
def get_settings() -> Settings:
    return Settings()