feat(service):lab4 add AttachmentService.Download via ObjectStorage

This commit is contained in:
Голиков Maximillian Антон
2026-10-21 18:19:34 +03:00
parent 21363f5b91
commit 15a2d7aa85
+15
View File
@@ -2,6 +2,7 @@ package service
import (
"context"
"io"
"strings"
"unicode"
"unicode/utf8"
@@ -43,6 +44,20 @@ func (s *AttachmentService) Get(ctx context.Context, userID, attachmentID string
return a, nil
}
func (s *AttachmentService) Download(
ctx context.Context,
userID, attachmentID string,
) (io.ReadCloser, int64, string, error) {
a, err := s.Get(ctx, userID, attachmentID)
if err != nil {
return nil, 0, "", err
}
if a.Status != domain.AttachmentStatusReady {
return nil, 0, "", &domain.ConflictError{Reason: "вложение не готово"}
}
return s.storage.Get(ctx, a.ObjectKey)
}
func (s *AttachmentService) ensureMember(ctx context.Context, userID, chatID string) error {
c, err := s.chats.GetByID(ctx, chatID)
if err != nil {