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:
|
def get_client() -> TelegramClient:
|
||||||
"""Build a Telethon client. Prefer StringSession from env (k8s-friendly),
|
"""Build a Telethon client.
|
||||||
fall back to file-based session at TG_SESSION_PATH for local dev."""
|
|
||||||
|
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
|
global _client
|
||||||
if _client is None:
|
if _client is None:
|
||||||
session = (
|
if settings.tg_session_string:
|
||||||
StringSession(settings.tg_session_string)
|
session = StringSession(settings.tg_session_string)
|
||||||
if settings.tg_session_string
|
else:
|
||||||
else settings.tg_session_path
|
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)
|
_client = TelegramClient(session, settings.tg_api_id, settings.tg_api_hash)
|
||||||
return _client
|
return _client
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user