From c58c3fe04458b1f03a69b25fd3e592f003adcbdf Mon Sep 17 00:00:00 2001 From: ywj <138745068+yangwenjie1231@users.noreply.github.com> Date: Sun, 15 Mar 2026 12:27:10 +0800 Subject: [PATCH] fix(feishu): resolve lint errors for shadow and formatting - Rename err variables to avoid shadowing in downloadExternalImage - Fix struct field alignment in TestExtractCardImageKeys Generated with Crush Assisted-by: GLM-5 via Crush --- pkg/channels/feishu/common_test.go | 112 ++++++++++++++--------------- pkg/channels/feishu/feishu_64.go | 10 +-- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/pkg/channels/feishu/common_test.go b/pkg/channels/feishu/common_test.go index ef747a269..ff4af0148 100644 --- a/pkg/channels/feishu/common_test.go +++ b/pkg/channels/feishu/common_test.go @@ -293,88 +293,88 @@ func TestStripMentionPlaceholders(t *testing.T) { func TestExtractCardImageKeys(t *testing.T) { tests := []struct { - name string - content string - wantFeishuKeys []string - wantExternalURLs []string + name string + content string + wantFeishuKeys []string + wantExternalURLs []string }{ { - name: "empty content", - content: "", - wantFeishuKeys: nil, - wantExternalURLs: nil, + name: "empty content", + content: "", + wantFeishuKeys: nil, + wantExternalURLs: nil, }, { - name: "invalid JSON", - content: "not json", - wantFeishuKeys: nil, - wantExternalURLs: nil, + name: "invalid JSON", + content: "not json", + wantFeishuKeys: nil, + wantExternalURLs: nil, }, { - name: "card with no images", - content: `{"schema":"2.0","body":{"elements":[{"tag":"markdown","content":"text"}]}}`, - wantFeishuKeys: nil, - wantExternalURLs: nil, + name: "card with no images", + content: `{"schema":"2.0","body":{"elements":[{"tag":"markdown","content":"text"}]}}`, + wantFeishuKeys: nil, + wantExternalURLs: nil, }, { - name: "single image with img_key", - content: `{"elements":[{"tag":"img","img_key":"img_abc123"}]}`, - wantFeishuKeys: []string{"img_abc123"}, - wantExternalURLs: nil, + name: "single image with img_key", + content: `{"elements":[{"tag":"img","img_key":"img_abc123"}]}`, + wantFeishuKeys: []string{"img_abc123"}, + wantExternalURLs: nil, }, { - name: "single image with src as Feishu key", - content: `{"elements":[{"tag":"img","src":"img_xyz789"}]}`, - wantFeishuKeys: []string{"img_xyz789"}, - wantExternalURLs: nil, + name: "single image with src as Feishu key", + content: `{"elements":[{"tag":"img","src":"img_xyz789"}]}`, + wantFeishuKeys: []string{"img_xyz789"}, + wantExternalURLs: nil, }, { - name: "multiple images", - content: `{"elements":[{"tag":"img","img_key":"img_1"},{"tag":"div","text":{"content":"text"}},{"tag":"img","img_key":"img_2"}]}`, - wantFeishuKeys: []string{"img_1", "img_2"}, - wantExternalURLs: nil, + name: "multiple images", + content: `{"elements":[{"tag":"img","img_key":"img_1"},{"tag":"div","text":{"content":"text"}},{"tag":"img","img_key":"img_2"}]}`, + wantFeishuKeys: []string{"img_1", "img_2"}, + wantExternalURLs: nil, }, { - name: "nested image in columns", - content: `{"elements":[{"tag":"div","columns":[{"tag":"img","img_key":"img_col1"},{"tag":"img","img_key":"img_col2"}]}]}`, - wantFeishuKeys: []string{"img_col1", "img_col2"}, - wantExternalURLs: nil, + name: "nested image in columns", + content: `{"elements":[{"tag":"div","columns":[{"tag":"img","img_key":"img_col1"},{"tag":"img","img_key":"img_col2"}]}]}`, + wantFeishuKeys: []string{"img_col1", "img_col2"}, + wantExternalURLs: nil, }, { - name: "image in action", - content: `{"elements":[{"tag":"action","actions":[{"tag":"img","img_key":"img_action"}]}]}`, - wantFeishuKeys: []string{"img_action"}, - wantExternalURLs: nil, + name: "image in action", + content: `{"elements":[{"tag":"action","actions":[{"tag":"img","img_key":"img_action"}]}]}`, + wantFeishuKeys: []string{"img_action"}, + wantExternalURLs: nil, }, { - name: "icon element", - content: `{"elements":[{"tag":"icon","icon_key":"icon_123"}]}`, - wantFeishuKeys: []string{"icon_123"}, - wantExternalURLs: nil, + name: "icon element", + content: `{"elements":[{"tag":"icon","icon_key":"icon_123"}]}`, + wantFeishuKeys: []string{"icon_123"}, + wantExternalURLs: nil, }, { - name: "complex card with text and images", - content: `{"header":{"title":{"content":"Title"}},"elements":[{"tag":"div","text":{"content":"Description"}},{"tag":"img","img_key":"img_main"}]}`, - wantFeishuKeys: []string{"img_main"}, - wantExternalURLs: nil, + name: "complex card with text and images", + content: `{"header":{"title":{"content":"Title"}},"elements":[{"tag":"div","text":{"content":"Description"}},{"tag":"img","img_key":"img_main"}]}`, + wantFeishuKeys: []string{"img_main"}, + wantExternalURLs: nil, }, { - name: "external URL in src", - content: `{"elements":[{"tag":"img","src":"https://example.com/image.png"}]}`, - wantFeishuKeys: nil, - wantExternalURLs: []string{"https://example.com/image.png"}, + name: "external URL in src", + content: `{"elements":[{"tag":"img","src":"https://example.com/image.png"}]}`, + wantFeishuKeys: nil, + wantExternalURLs: []string{"https://example.com/image.png"}, }, { - name: "mixed Feishu keys and external URLs", - content: `{"elements":[{"tag":"img","img_key":"img_feishu"},{"tag":"img","src":"https://cdn.example.com/external.jpg"},{"tag":"img","src":"img_another"}]}`, - wantFeishuKeys: []string{"img_feishu", "img_another"}, - wantExternalURLs: []string{"https://cdn.example.com/external.jpg"}, + name: "mixed Feishu keys and external URLs", + content: `{"elements":[{"tag":"img","img_key":"img_feishu"},{"tag":"img","src":"https://cdn.example.com/external.jpg"},{"tag":"img","src":"img_another"}]}`, + wantFeishuKeys: []string{"img_feishu", "img_another"}, + wantExternalURLs: []string{"https://cdn.example.com/external.jpg"}, }, { - name: "multiple external URLs", - content: `{"elements":[{"tag":"img","src":"https://a.com/1.png"},{"tag":"img","src":"http://b.com/2.jpg"}]}`, - wantFeishuKeys: nil, - wantExternalURLs: []string{"https://a.com/1.png", "http://b.com/2.jpg"}, + name: "multiple external URLs", + content: `{"elements":[{"tag":"img","src":"https://a.com/1.png"},{"tag":"img","src":"http://b.com/2.jpg"}]}`, + wantFeishuKeys: nil, + wantExternalURLs: []string{"https://a.com/1.png", "http://b.com/2.jpg"}, }, } diff --git a/pkg/channels/feishu/feishu_64.go b/pkg/channels/feishu/feishu_64.go index 9e93a6fd5..7d118be4b 100644 --- a/pkg/channels/feishu/feishu_64.go +++ b/pkg/channels/feishu/feishu_64.go @@ -753,25 +753,25 @@ func (c *FeishuChannel) downloadExternalImage( return "" } - if _, err := io.Copy(out, resp.Body); err != nil { + if _, copyErr := io.Copy(out, resp.Body); copyErr != nil { out.Close() os.Remove(localPath) logger.ErrorCF("feishu", "Failed to write external image to file", map[string]any{ - "error": err.Error(), + "error": copyErr.Error(), }) return "" } out.Close() // Store in MediaStore - ref, err := store.Store(localPath, media.MediaMeta{ + ref, storeErr := store.Store(localPath, media.MediaMeta{ Filename: filename, Source: "feishu_external", }, scope) - if err != nil { + if storeErr != nil { logger.ErrorCF("feishu", "Failed to store external image", map[string]any{ "url": imageURL, - "error": err.Error(), + "error": storeErr.Error(), }) os.Remove(localPath) return ""