fix: address Base attachment review follow-ups (#958)

This commit is contained in:
zgz2048
2026-05-19 13:20:07 +08:00
committed by GitHub
parent 2bb69d1942
commit 3354494579
3 changed files with 32 additions and 2 deletions

View File

@@ -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"]}}}}`

View File

@@ -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

View File

@@ -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}