Ensure Telegram session directory exists
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 28s

This commit is contained in:
Grendgi
2026-06-04 16:35:29 +03:00
parent 771ea97156
commit e736573d6f

View File

@@ -146,15 +146,19 @@ _client: TelegramClient | None = None
def get_client() -> TelegramClient:
"""Build a Telethon client. Prefer StringSession from env (k8s-friendly),
fall back to file-based session at TG_SESSION_PATH for local dev."""
"""Build a Telethon client.
Prefer StringSession from k8s Secret, otherwise use the file-based session
path on the mounted PVC so Portal auth can persist between restarts.
"""
global _client
if _client is None:
session = (
StringSession(settings.tg_session_string)
if settings.tg_session_string
else settings.tg_session_path
)
if settings.tg_session_string:
session = StringSession(settings.tg_session_string)
else:
session_path = Path(settings.tg_session_path)
session_path.parent.mkdir(parents=True, exist_ok=True)
session = str(session_path)
_client = TelegramClient(session, settings.tg_api_id, settings.tg_api_hash)
return _client