From 0ab486713013a9ff34313f44f2f822be63db3e39 Mon Sep 17 00:00:00 2001 From: fengsilin Date: Fri, 21 Aug 2026 10:56:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(channel):=20=E4=BF=AE=E5=A4=8D=E8=B1=86?= =?UTF-8?q?=E5=8C=85=E8=A7=86=E9=A2=91=E6=B8=A0=E9=81=93=E7=B4=A0=E6=9D=90?= =?UTF-8?q?=E5=87=AD=E6=8D=AE=E6=91=98=E8=A6=81=E4=B8=8D=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit attachChannelAssetCredentialSummaries 收集查询 ID 时只纳入了中国移动 Seedance(61) 渠道,豆包视频(54) 渠道的凭据永远不会回显,导致管理端 编辑 54 渠道时素材 API 地址显示为空。提取 isAssetCredentialSummaryChannel 统一两处类型判断,并补充 54 渠道回归测试。 --- controller/channel.go | 9 +++++-- controller/channel_asset_credential_test.go | 26 +++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/controller/channel.go b/controller/channel.go index 4495ef6..6b38312 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -70,10 +70,15 @@ func clearChannelInfo(channel *model.Channel) { } } +func isAssetCredentialSummaryChannel(channel *model.Channel) bool { + return channel != nil && (channel.Type == constant.ChannelTypeChinaMobileSeedance || + channel.Type == constant.ChannelTypeDoubaoVideo) +} + func attachChannelAssetCredentialSummaries(channels []*model.Channel) error { ids := make([]int, 0) for _, channel := range channels { - if channel != nil && channel.Type == constant.ChannelTypeChinaMobileSeedance { + if isAssetCredentialSummaryChannel(channel) { ids = append(ids, channel.Id) } } @@ -82,7 +87,7 @@ func attachChannelAssetCredentialSummaries(channels []*model.Channel) error { return err } for _, channel := range channels { - if channel == nil || (channel.Type != constant.ChannelTypeChinaMobileSeedance && channel.Type != constant.ChannelTypeDoubaoVideo) { + if !isAssetCredentialSummaryChannel(channel) { continue } summary, ok := summaries[channel.Id] diff --git a/controller/channel_asset_credential_test.go b/controller/channel_asset_credential_test.go index f87a56c..54c7ab3 100644 --- a/controller/channel_asset_credential_test.go +++ b/controller/channel_asset_credential_test.go @@ -33,18 +33,36 @@ func setupChannelAssetCredentialControllerDB(t *testing.T) *gorm.DB { func TestAttachChannelAssetCredentialSummariesDoesNotExposeSecrets(t *testing.T) { db := setupChannelAssetCredentialControllerDB(t) + accessKey := "ak-" + t.Name() + secretKey := "sk-" + t.Name() channel := &model.Channel{Id: 61, Type: constant.ChannelTypeChinaMobileSeedance, Key: "video-key", Name: "channel"} require.NoError(t, db.Create(channel).Error) require.NoError(t, model.UpsertChannelAssetCredential(&model.ChannelAssetCredential{ ChannelId: 61, - AccessKey: "ak-secret", - SecretKey: "sk-secret", + AccessKey: accessKey, + SecretKey: secretKey, PoolID: "pool-61", })) require.NoError(t, attachChannelAssetCredentialSummaries([]*model.Channel{channel})) assert.True(t, channel.AssetCredentialConfigured) assert.Equal(t, "pool-61", channel.AssetCredentialPoolID) - assert.NotContains(t, channel.Key, "ak-secret") - assert.NotContains(t, channel.Key, "sk-secret") + assert.NotContains(t, channel.Key, accessKey) + assert.NotContains(t, channel.Key, secretKey) +} + +func TestAttachChannelAssetCredentialSummariesIncludesDoubaoVideo(t *testing.T) { + db := setupChannelAssetCredentialControllerDB(t) + channel := &model.Channel{Id: 54, Type: constant.ChannelTypeDoubaoVideo, Key: "video-key", Name: "doubao"} + require.NoError(t, db.Create(channel).Error) + require.NoError(t, model.UpsertChannelAssetCredential(&model.ChannelAssetCredential{ + ChannelId: 54, + AccessKey: "ak-" + t.Name(), + SecretKey: "sk-" + t.Name(), + BaseURL: "http://example.com/openApi/portrait", + })) + + require.NoError(t, attachChannelAssetCredentialSummaries([]*model.Channel{channel})) + assert.True(t, channel.AssetCredentialConfigured) + assert.Equal(t, "http://example.com/openApi/portrait", channel.AssetCredentialBaseURL) }