diff --git a/shortcuts/base/base_execute_test.go b/shortcuts/base/base_execute_test.go index d21984000..0a9a1d709 100644 --- a/shortcuts/base/base_execute_test.go +++ b/shortcuts/base/base_execute_test.go @@ -1909,7 +1909,7 @@ func TestBaseRecordExecuteReadCreateDelete(t *testing.T) { } }) - t.Run("download attachment uses extra info", func(t *testing.T) { + t.Run("download attachment includes extra query parameter", func(t *testing.T) { factory, stdout, reg := newExecuteFactory(t) extra := `{"bitablePerm":{"tableId":"tbl_x","attachments":{"fld_att":{"rec_x":["box_a"]}}}}` diff --git a/shortcuts/base/record_upload_attachment.go b/shortcuts/base/record_upload_attachment.go index 6414577cd..057565246 100644 --- a/shortcuts/base/record_upload_attachment.go +++ b/shortcuts/base/record_upload_attachment.go @@ -499,7 +499,7 @@ func uploadAttachmentToBase(runtime *common.RuntimeContext, filePath, fileName, if width, height, ok := detectAttachmentImageDimensions(runtime.FileIO(), filePath, mimeType); ok { attachment["image_width"] = width attachment["image_height"] = height - } else if strings.HasPrefix(mimeType, "image/") { + } else if attachmentImageDimensionsWarningEnabled(mimeType) { fmt.Fprintf(runtime.IO().ErrOut, "Warning: image dimensions unavailable for %s; attachment may display as square\n", fileName) } return attachment, nil @@ -574,6 +574,15 @@ func detectAttachmentImageDimensions(fio fileio.FileIO, filePath string, mimeTyp return cfg.Width, cfg.Height, true } +func attachmentImageDimensionsWarningEnabled(mimeType string) bool { + switch mimeType { + case "image/gif", "image/jpeg", "image/png": + return true + default: + return false + } +} + type baseAttachmentDownloadItem struct { RecordID string FieldID string diff --git a/shortcuts/base/record_upload_attachment_test.go b/shortcuts/base/record_upload_attachment_test.go index a68252099..eaf9b138d 100644 --- a/shortcuts/base/record_upload_attachment_test.go +++ b/shortcuts/base/record_upload_attachment_test.go @@ -100,6 +100,27 @@ func TestDetectAttachmentImageDimensions(t *testing.T) { } } +func TestAttachmentImageDimensionsWarningEnabled(t *testing.T) { + tests := []struct { + mimeType string + want bool + }{ + {mimeType: "image/gif", want: true}, + {mimeType: "image/jpeg", want: true}, + {mimeType: "image/png", want: true}, + {mimeType: "image/webp", want: false}, + {mimeType: "application/pdf", want: false}, + } + + for _, tt := range tests { + t.Run(tt.mimeType, func(t *testing.T) { + if got := attachmentImageDimensionsWarningEnabled(tt.mimeType); got != tt.want { + t.Fatalf("attachmentImageDimensionsWarningEnabled(%q) = %v, want %v", tt.mimeType, got, tt.want) + } + }) + } +} + func TestDetectAttachmentMIMETypeWrapsOpenError(t *testing.T) { fio := attachmentTestFileIO{openErr: os.ErrNotExist}