62 lines
2.9 KiB
Python
62 lines
2.9 KiB
Python
## Copyright © 2026 Olaf Kolkman
|
|
## SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from dataclasses import dataclass
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
DB_PATH = BASE_DIR / 'data' / 'linklog.db'
|
|
|
|
|
|
def normalize_public_url(value: str) -> str:
|
|
value = value.strip().rstrip('/')
|
|
if '://' in value:
|
|
return value
|
|
scheme = 'http' if value.startswith(('localhost', '127.0.0.1')) else 'https'
|
|
return f'{scheme}://{value}'
|
|
|
|
|
|
@dataclass
|
|
class Settings:
|
|
app_name: str = os.getenv('LINKLOG_APP_NAME', 'LinkLog')
|
|
version: str = os.getenv('LINKLOG_VERSION', '0.1.0')
|
|
database_url: str = os.getenv('LINKLOG_DATABASE_URL', f'sqlite:///{DB_PATH}')
|
|
secret_key: str = os.getenv('LINKLOG_SECRET_KEY', 'dev-secret-key-change-me')
|
|
data_encryption_key: str = os.getenv('LINKLOG_DATA_ENCRYPTION_KEY', '')
|
|
token_expiry_minutes: int = int(os.getenv('LINKLOG_TOKEN_EXPIRY_MINUTES', '15'))
|
|
refresh_token_expiry_days: int = int(os.getenv('LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS', '30'))
|
|
public_url: str = normalize_public_url(os.getenv('LINKLOG_PUBLIC_URL', 'linklog.example.com'))
|
|
smtp_host: str = os.getenv('LINKLOG_SMTP_HOST', '')
|
|
smtp_port: int = int(os.getenv('LINKLOG_SMTP_PORT', '587'))
|
|
smtp_username: str = os.getenv('LINKLOG_SMTP_USERNAME', '')
|
|
smtp_password: str = os.getenv('LINKLOG_SMTP_PASSWORD', '')
|
|
smtp_from: str = os.getenv('LINKLOG_SMTP_FROM', 'LinkLog <no-reply@localhost>')
|
|
smtp_use_tls: bool = os.getenv('LINKLOG_SMTP_USE_TLS', 'true').lower() in {'1', 'true', 'yes'}
|
|
email_verification_expiry_hours: int = int(os.getenv('LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS', '24'))
|
|
password_reset_expiry_hours: int = int(os.getenv('LINKLOG_PASSWORD_RESET_EXPIRY_HOURS', '1'))
|
|
mastodon_client_name: str = os.getenv('LINKLOG_MASTODON_CLIENT_NAME', 'LinkLog')
|
|
mastodon_oauth_expiry_minutes: int = int(os.getenv('LINKLOG_MASTODON_OAUTH_EXPIRY_MINUTES', '10'))
|
|
log_level: str = os.getenv('LINKLOG_LOG_LEVEL', 'INFO').upper()
|
|
tracking_params: list[str] = None
|
|
|
|
def __post_init__(self):
|
|
if self.tracking_params is None:
|
|
default_tracking_params = [
|
|
'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',
|
|
'utm_id', 'utm_name', 'gclid', 'fbclid', 'dclid', 'msclkid', 'mc_cid',
|
|
'mc_eid', 'igshid', 'ga_source', 'ga_medium', 'ga_campaign', 'ga_place',
|
|
'campaignid', 'hsa_cr', 'hsa_cam', 'hsa_grp', 'hsa_ad', 'hsa_src',
|
|
'hsa_acc', 'hsa_net', 'hsa_mt', 'hsa_kw', 'hsa_ver', 'hsa_tgt',
|
|
]
|
|
configured_params = os.getenv('LINKLOG_TRACKING_PARAMS')
|
|
self.tracking_params = (
|
|
[item.strip() for item in configured_params.split(',') if item.strip()]
|
|
if configured_params
|
|
else default_tracking_params
|
|
)
|
|
|
|
|
|
settings = Settings()
|