Spaces:
Sleeping
Sleeping
File size: 1,129 Bytes
f48f5c4 51c39cf f48f5c4 51c39cf 39f81e0 f48f5c4 51c39cf 39f81e0 f48f5c4 | 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 | from __future__ import annotations
import os
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from typing import List
def _split_csv(value: str | None, *, fallback: List[str]) -> List[str]:
if not value:
return fallback
return [item.strip() for item in value.split(",") if item.strip()]
@dataclass(frozen=True)
class Settings:
app_name: str
api_prefix: str
cors_origins: List[str]
storage_dir: Path
max_upload_mb: int
frontend_base_url: str
pdf_timeout_ms: int
@lru_cache
def get_settings() -> Settings:
return Settings(
app_name=os.getenv("APP_NAME", "Starter API"),
api_prefix=os.getenv("API_PREFIX", "/api"),
cors_origins=_split_csv(
os.getenv("CORS_ORIGINS"), fallback=["http://localhost:5173"]
),
storage_dir=Path(os.getenv("STORAGE_DIR", "data")).resolve(),
max_upload_mb=int(os.getenv("MAX_UPLOAD_MB", "50")),
frontend_base_url=os.getenv("FRONTEND_BASE_URL", "http://localhost:5173"),
pdf_timeout_ms=int(os.getenv("PDF_TIMEOUT_MS", "90000")),
)
|