Реализовать асинхронную обработку вложений

This commit is contained in:
2026-11-17 18:21:09 +03:00
parent 4d54ba3848
commit e8becaf761
51 changed files with 2234 additions and 58 deletions
+6 -8
View File
@@ -14,7 +14,7 @@ router = APIRouter(tags=['attachments'])
@router.post(
'/api/v1/chats/{chat_id}/attachments',
status_code=201,
status_code=202,
response_model=AttachmentOut,
)
async def upload(
@@ -51,16 +51,14 @@ async def content(
actor: User = Depends(current_user),
attachments: AttachmentService = Depends(attachment_service),
) -> StreamingResponse:
if variant != 'original':
from ...domain.errors import NotFound
raise NotFound('вариант вложения не найден')
attachment, stream = await attachments.content(actor, attachment_id)
attachment, stream, content_type, size_bytes = await attachments.content(
actor, attachment_id, variant
)
return StreamingResponse(
stream.chunks(),
media_type=attachment.content_type,
media_type=content_type,
headers={
'Content-Length': str(attachment.size_bytes),
'Content-Length': str(size_bytes),
'Content-Disposition': f'inline; filename="attachment-{attachment.id}"',
},
)