s3
This commit is contained in:
@@ -26,12 +26,20 @@ async def create_creative(
|
||||
|
||||
creative_text = domain.replace_invite_link_with_tag(input.text)
|
||||
|
||||
media_s3_key: str | None = None
|
||||
if input.media_data:
|
||||
file_id = uuid.uuid4()
|
||||
media_s3_key = f'creatives/{workspace_id}/{file_id}'
|
||||
content_type = _get_content_type(input.media_type)
|
||||
await self.s3.upload(media_s3_key, input.media_data, content_type)
|
||||
log.info('Uploaded creative media to S3: %s', media_s3_key)
|
||||
|
||||
creative = domain.Creative(
|
||||
name=input.name,
|
||||
text=creative_text,
|
||||
media_type=input.media_type,
|
||||
media_file_id=input.media_file_id,
|
||||
media_data=input.media_data,
|
||||
media_s3_key=media_s3_key,
|
||||
buttons=[button.model_dump() for button in input.buttons],
|
||||
status=domain.CreativeStatus.ACTIVE,
|
||||
project_id=project.id,
|
||||
@@ -52,3 +60,16 @@ async def create_creative(
|
||||
status=creative.status,
|
||||
placements_count=0,
|
||||
)
|
||||
|
||||
|
||||
def _get_content_type(media_type: str | None) -> str:
|
||||
"""Map Telegram media type to MIME content type."""
|
||||
if not media_type:
|
||||
return 'application/octet-stream'
|
||||
|
||||
mapping = {
|
||||
'photo': 'image/jpeg',
|
||||
'video': 'video/mp4',
|
||||
'animation': 'image/gif',
|
||||
}
|
||||
return mapping.get(media_type, 'application/octet-stream')
|
||||
|
||||
Reference in New Issue
Block a user