github-actions[bot]
Automated Deploy: 83f1f6fa59ef9d22788ee608e3ba12967f91dd5c
ae2c68f
Raw History Blame Contribute Delete
825 Bytes
"""Short-lived read URLs for stored media. Every module that returns a MediaRef builds it here."""
from datetime import UTC, datetime, timedelta
from uuid import UUID
from app.common.schemas import MediaRef
from app.integrations.storage import StorageClient
from app.modules.uploads.models import Upload
def media_ref(storage: StorageClient, upload_id: UUID, object_key: str, seconds: float | None = None) -> MediaRef:
return MediaRef(upload_id=upload_id, url=storage.presign_get(object_key),
expires_at=datetime.now(UTC) + timedelta(seconds=storage.download_ttl), seconds=seconds)
def upload_ref(storage: StorageClient, upload: Upload | None, seconds: float | None = None) -> MediaRef | None:
return media_ref(storage, upload.id, upload.object_key, seconds) if upload is not None else None