27 lines
845 B
Python
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,
|
|
)
|