Dateien als Clip-Art "file": gestreamter Upload mit Größengrenze, Kontingent pro Benutzer und Mindestreserve an freiem Speicher. Download immer als Anhang mit sandbox-CSP, Vorschau nur für geprüfte JPEG/PNG/GIF/WebP. Ablauf nach 1/7/30 Tagen oder nie; der Aufräumjob löscht abgelaufene und verwaiste Dateien. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# Only real environment variables; compose passes .env via env_file. Reading a .env
|
|
# file here would leak the deployment config into tests run from the project root.
|
|
model_config = SettingsConfigDict(extra="ignore")
|
|
|
|
data_dir: Path = Path("/data")
|
|
static_dir: Path = Path("/app/static")
|
|
log_level: str = "info"
|
|
enable_api_docs: bool = False
|
|
max_request_bytes: int = 1024 * 1024
|
|
|
|
# Comma-separated list of origins allowed for state-changing requests and WebSockets
|
|
allowed_origins: str = "https://clip.webbildhauer.com"
|
|
cookie_secure: bool = True
|
|
|
|
session_idle_days: int = 30
|
|
session_max_days: int = 90
|
|
|
|
login_max_failures_per_user: int = 5
|
|
login_max_failures_per_ip: int = 20
|
|
login_failure_window_minutes: int = 15
|
|
# Only meaningful once the real client IP is known (FORWARDED_ALLOW_IPS set to the proxy)
|
|
login_ip_lockout: bool = False
|
|
|
|
clip_max_chars: int = 200_000
|
|
|
|
file_max_bytes: int = 100 * 1024 * 1024
|
|
file_quota_bytes: int = 1024 * 1024 * 1024
|
|
# Uploads are refused when the disk would drop below this; the server is shared
|
|
file_min_free_bytes: int = 2 * 1024 * 1024 * 1024
|
|
|
|
initial_admin_username: str | None = None
|
|
initial_admin_password: str | None = None
|
|
|
|
@property
|
|
def database_url(self) -> str:
|
|
return f"sqlite:///{self.data_dir / 'app.db'}"
|
|
|
|
@property
|
|
def files_dir(self) -> Path:
|
|
return self.data_dir / "files"
|
|
|
|
@property
|
|
def allowed_origin_list(self) -> list[str]:
|
|
return [o.strip().rstrip("/") for o in self.allowed_origins.split(",") if o.strip()]
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|