Corp/backend/communications/media_delivery.py
lizerk 2768d2f1b3
Some checks failed
Deploy production / deploy (push) Failing after 14m49s
Restore reliable chat realtime and media playback
2026-09-10 20:26:58 +03:00

27 lines
845 B
Python

"""Private chat media locations; no direct storage URLs leave the API."""
from django.conf import settings
from eusrr_backend.protected_media import protected_file_response
def attachment_endpoint(attachment, *, thumbnail=False):
if not attachment.message_id:
return None
suffix = "thumbnail/" if thumbnail else ""
return (
f"/api/v1/communications/messages/{attachment.message_id}/"
f"attachments/{attachment.pk}/{suffix}"
)
def chat_file_response(file, *, filename, as_attachment=True):
return protected_file_response(
file,
filename=filename,
storage_directory="chat_attachments",
internal_prefix="/_protected_chat_attachments/",
use_x_accel=getattr(settings, "CHAT_ATTACHMENTS_USE_X_ACCEL_REDIRECT", False),
as_attachment=as_attachment,
)