improve work

This commit is contained in:
root committed 2025-10-01 13:19:03 +00:00
1 parent 64491e19e1
commit 3511ebd247
23 files changed
+1595 -310

No files matched your search

+2 -1
View File
@@ -2,8 +2,9 @@ from app.core.content.content_id import ContentId
def resolve_content(content_id) -> ContentId: # -> [content, error]
if isinstance(content_id, ContentId):
return content_id, None
try:
return ContentId.deserialize(content_id), None
except BaseException as e:
return None, f"{e}"
+24
View File
@@ -0,0 +1,24 @@
from typing import Optional
from urllib.parse import urlencode
STARTAPP_SEPARATOR = '!'
STARTAPP_LIMIT = 64
def build_content_links(content_token: str, ref_id: Optional[str], *, project_host: str, bot_username: str):
"""Return tuple of (startapp_payload, telegram_url, web_url)."""
payload = content_token
short_ref = (ref_id or '').strip()[:3]
if short_ref:
candidate = f"{content_token}{STARTAPP_SEPARATOR}{short_ref}"
if len(candidate) <= STARTAPP_LIMIT:
payload = candidate
telegram_url = f"https://t.me/{bot_username}/content?startapp={payload}"
query = [('content', content_token)]
if ref_id:
query.append(('ref', ref_id))
web_url = f"{project_host}/viewContent?{urlencode(query)}"
return payload, telegram_url, web_url