feat(service):lab4 add AttachmentService.Download via ObjectStorage
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user