feat(api): lab5 serve attachment variants in json and content endpoints

This commit is contained in:
Голиков Maximillian Антон
2026-11-09 14:51:17 +03:00
parent 22c876f63c
commit bb5f2fb237
4 changed files with 27 additions and 8 deletions
+13 -2
View File
@@ -167,7 +167,7 @@ func (s *AttachmentService) Get(ctx context.Context, userID, attachmentID string
func (s *AttachmentService) Download(
ctx context.Context,
userID, attachmentID string,
userID, attachmentID, variantName string,
) (io.ReadCloser, int64, string, error) {
a, err := s.Get(ctx, userID, attachmentID)
if err != nil {
@@ -176,7 +176,18 @@ func (s *AttachmentService) Download(
if a.Status != domain.AttachmentStatusReady {
return nil, 0, "", &domain.ConflictError{Reason: "вложение не готово"}
}
return s.storage.Get(ctx, a.ObjectKey)
if variantName == "original" || variantName == "" {
return s.storage.Get(ctx, a.ObjectKey)
}
for _, v := range a.Variants {
if v.Name == variantName {
return s.storage.Get(ctx, v.ObjectKey)
}
}
return nil, 0, "", &domain.NotFoundError{Entity: "variant", ID: variantName}
}
func (s *AttachmentService) ensureMember(ctx context.Context, userID, chatID string) error {