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