feat(api): lab5 serve attachment variants in json and content endpoints
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user