70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
import os
|
|
|
|
def getenv_bool(key: str, default: bool = False) -> bool:
|
|
v = os.getenv(key)
|
|
if v is None:
|
|
return default
|
|
return v.lower() in ("1", "true", "t", "yes", "y", "on")
|
|
|
|
def getenv_int(key: str, default: int) -> int:
|
|
try:
|
|
return int(os.getenv(key, str(default)))
|
|
except ValueError:
|
|
return default
|
|
|
|
def getenv_float(key: str, default: float) -> float:
|
|
try:
|
|
return float(os.getenv(key, str(default)))
|
|
except ValueError:
|
|
return default
|
|
|
|
# Podstawowe
|
|
FLASK_DEBUG = getenv_bool("FLASK_DEBUG", True)
|
|
SECRET_KEY = os.getenv("SECRET_KEY", "secretkey")
|
|
|
|
# Rozmiary/limity
|
|
MAX_CONTENT_LENGTH = getenv_int("MAX_CONTENT_LENGTH", 50 * 1024 * 1024) # 50MB
|
|
RATE_LIMIT_DEFAULT = os.getenv("RATE_LIMIT_DEFAULT", "100 per minute")
|
|
RATE_LIMIT_CONVERT = os.getenv("RATE_LIMIT_CONVERT", "100 per minute")
|
|
|
|
# Redis
|
|
REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/7")
|
|
REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
|
|
REDIS_PORT = getenv_int("REDIS_PORT", 6379)
|
|
REDIS_DB = getenv_int("REDIS_DB", 7)
|
|
|
|
# Basic Auth dla /stats
|
|
STATS_BASIC_AUTH_ENABLED = getenv_bool("STATS_BASIC_AUTH_ENABLED", True)
|
|
STATS_BASIC_AUTH_REALM = os.getenv("STATS_BASIC_AUTH_REALM", "Stats")
|
|
STATS_BASIC_AUTH_USER = os.getenv("STATS_BASIC_AUTH_USER", "admin").strip()
|
|
STATS_BASIC_AUTH_PASS = os.getenv("STATS_BASIC_AUTH_PASS", "admin").strip()
|
|
|
|
# Cache/ETag dla Varnisha
|
|
CACHE_ENABLED = getenv_bool("CACHE_ENABLED", True)
|
|
CACHE_S_MAXAGE = getenv_int("CACHE_S_MAXAGE", 43200) # 12h
|
|
CACHE_MAX_AGE = getenv_int("CACHE_MAX_AGE", 3600) # 1h
|
|
USE_REDIS_BODY_CACHE = getenv_bool("USE_REDIS_BODY_CACHE", False)
|
|
|
|
# AIOHTTP/stream
|
|
AIOHTTP_TOTAL_TIMEOUT = getenv_float("AIOHTTP_TOTAL_TIMEOUT", 70.0)
|
|
AIOHTTP_CONNECT_TIMEOUT = getenv_float("AIOHTTP_CONNECT_TIMEOUT", 10.0)
|
|
AIOHTTP_SOCK_CONNECT_TIMEOUT= getenv_float("AIOHTTP_SOCK_CONNECT_TIMEOUT", 10.0)
|
|
AIOHTTP_SOCK_READ_TIMEOUT = getenv_float("AIOHTTP_SOCK_READ_TIMEOUT", 60.0)
|
|
|
|
READ_CHUNK = getenv_int("READ_CHUNK", 64 * 1024) # 64 KiB
|
|
STREAM_LINE_LIMIT= getenv_int("STREAM_LINE_LIMIT", 4096)
|
|
|
|
# Serwer
|
|
BIND_HOST = os.getenv("BIND_HOST", "127.0.0.1")
|
|
BIND_PORT = getenv_int("BIND_PORT", 8283)
|
|
|
|
# Domyślny URL źródłowy (opcjonalny)
|
|
DEFAULT_SOURCE_URL = os.getenv(
|
|
"DEFAULT_SOURCE_URL",
|
|
""
|
|
)
|
|
|
|
# Debug trybu /convert
|
|
DEBUG_ENABLE = getenv_bool("DEBUG_ENABLE", False)
|
|
DEBUG_KEY = os.getenv("DEBUG_KEY", "") # ustaw w env bezpieczny losowy sekret
|
|
DEBUG_RATE_LIMIT = os.getenv("DEBUG_RATE_LIMIT", "5 per minute") |