@@ -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
125125func (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
197206func (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
0 commit comments