Ensure Telegram session directory exists
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 28s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 28s
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user