Skip to content

Commit d009c1d

Browse files
committed
Pass workspace settings as paramter to convertAttachmentFromStore
1 parent adfdcaa commit d009c1d

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

server/router/api/v1/attachment_service.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (s *APIV1Service) CreateAttachment(ctx context.Context, request *v1pb.Creat
119119
return nil, status.Errorf(codes.Internal, "failed to create attachment: %v", err)
120120
}
121121

122-
return s.convertAttachmentFromStore(ctx, attachment), nil
122+
return convertAttachmentFromStore(attachment, workspaceStorageSetting), nil
123123
}
124124

125125
func (s *APIV1Service) ListAttachments(ctx context.Context, request *v1pb.ListAttachmentsRequest) (*v1pb.ListAttachmentsResponse, error) {
@@ -161,10 +161,15 @@ func (s *APIV1Service) ListAttachments(ctx context.Context, request *v1pb.ListAt
161161
return nil, status.Errorf(codes.Internal, "failed to list attachments: %v", err)
162162
}
163163

164+
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
165+
if err != nil {
166+
return nil, status.Errorf(codes.Internal, "failed to get workspace storage setting: %v", err)
167+
}
168+
164169
response := &v1pb.ListAttachmentsResponse{}
165170

166171
for _, attachment := range attachments {
167-
response.Attachments = append(response.Attachments, s.convertAttachmentFromStore(ctx, attachment))
172+
response.Attachments = append(response.Attachments, convertAttachmentFromStore(attachment, workspaceStorageSetting))
168173
}
169174

170175
// For simplicity, set total size to the number of returned attachments.
@@ -191,7 +196,11 @@ func (s *APIV1Service) GetAttachment(ctx context.Context, request *v1pb.GetAttac
191196
if attachment == nil {
192197
return nil, status.Errorf(codes.NotFound, "attachment not found")
193198
}
194-
return s.convertAttachmentFromStore(ctx, attachment), nil
199+
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
200+
if err != nil {
201+
return nil, status.Errorf(codes.Internal, "failed to get workspace storage setting: %v", err)
202+
}
203+
return convertAttachmentFromStore(attachment, workspaceStorageSetting), nil
195204
}
196205

197206
func (s *APIV1Service) GetAttachmentBinary(ctx context.Context, request *v1pb.GetAttachmentBinaryRequest) (*httpbody.HttpBody, error) {
@@ -381,7 +390,7 @@ func (s *APIV1Service) DeleteAttachment(ctx context.Context, request *v1pb.Delet
381390
return &emptypb.Empty{}, nil
382391
}
383392

384-
func (s *APIV1Service) convertAttachmentFromStore(ctx context.Context, attachment *store.Attachment) *v1pb.Attachment {
393+
func convertAttachmentFromStore(attachment *store.Attachment, workspaceStorageSetting *storepb.WorkspaceStorageSetting) *v1pb.Attachment {
385394
attachmentMessage := &v1pb.Attachment{
386395
Name: fmt.Sprintf("%s%s", AttachmentNamePrefix, attachment.UID),
387396
CreateTime: timestamppb.New(time.Unix(attachment.CreatedTs, 0)),
@@ -398,14 +407,9 @@ func (s *APIV1Service) convertAttachmentFromStore(ctx context.Context, attachmen
398407
}
399408

400409
// Populate use_thumbnail_for_s3_image based on workspace setting and storage type
401-
if attachment.StorageType == storepb.AttachmentStorageType_S3 {
402-
storageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
403-
if err != nil {
404-
slog.Warn("failed to get workspace storage setting", slog.Any("error", err))
405-
} else {
406-
useThumbnail := storageSetting.UseThumbnailsForS3Images
407-
attachmentMessage.UseThumbnailForS3Image = &useThumbnail
408-
}
410+
if attachment.StorageType == storepb.AttachmentStorageType_S3 && workspaceStorageSetting != nil {
411+
useThumbnail := workspaceStorageSetting.UseThumbnailsForS3Images
412+
attachmentMessage.UseThumbnailForS3Image = &useThumbnail
409413
}
410414

411415
return attachmentMessage

server/router/api/v1/memo_attachment_service.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,16 @@ func (s *APIV1Service) ListMemoAttachments(ctx context.Context, request *v1pb.Li
9292
return nil, status.Errorf(codes.Internal, "failed to list attachments: %v", err)
9393
}
9494

95+
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
96+
if err != nil {
97+
return nil, status.Errorf(codes.Internal, "failed to get workspace storage setting: %v", err)
98+
}
99+
95100
response := &v1pb.ListMemoAttachmentsResponse{
96101
Attachments: []*v1pb.Attachment{},
97102
}
98103
for _, attachment := range attachments {
99-
response.Attachments = append(response.Attachments, s.convertAttachmentFromStore(ctx, attachment))
104+
response.Attachments = append(response.Attachments, convertAttachmentFromStore(attachment, workspaceStorageSetting))
100105
}
101106
return response, nil
102107
}

server/router/api/v1/memo_service_converter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
2525
displayTs = memo.UpdatedTs
2626
}
2727

28+
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
29+
if err != nil {
30+
return nil, errors.Wrap(err, "failed to get workspace storage setting")
31+
}
32+
2833
name := fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID)
2934
memoMessage := &v1pb.Memo{
3035
Name: name,
@@ -64,7 +69,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
6469
memoMessage.Attachments = []*v1pb.Attachment{}
6570

6671
for _, attachment := range attachments {
67-
attachmentResponse := s.convertAttachmentFromStore(ctx, attachment)
72+
attachmentResponse := convertAttachmentFromStore(attachment, workspaceStorageSetting)
6873
memoMessage.Attachments = append(memoMessage.Attachments, attachmentResponse)
6974
}
7075

0 commit comments

Comments
 (0)