fix(api): 模型计价 - 兼容图片分辨率字段拼写并校验能力
This commit is contained in:
@@ -219,7 +219,17 @@ func TestRepriceTierFieldValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBatchRepricingRollsBackOnConcurrentChange(t *testing.T) {
|
||||
func TestNormalizeChannelModelTierSelectorAcceptsResolutionTypo(t *testing.T) {
|
||||
selector, resolution, videoSeconds, err := normalizeChannelModelTierSelector("image", ChannelModelPriceTierRequest{
|
||||
Selector: map[string]string{"resoluton": "2K"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if selector["resolution"] != "2k" || selector["resoluton"] != "" || resolution != "*" || videoSeconds != 0 {
|
||||
t.Fatalf("selector=%v resolution=%q videoSeconds=%d", selector, resolution, videoSeconds)
|
||||
}
|
||||
}
|
||||
for _, target := range []string{"model", "tier"} {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
svc, db, _ := seedRepricingModels(t)
|
||||
|
||||
@@ -144,6 +144,10 @@ func normalizeChannelModelTierSelector(capability string, input ChannelModelPric
|
||||
}
|
||||
case "vquality":
|
||||
value = normalizeChannelModelTierResolution(value)
|
||||
case "resolution", "resoluton":
|
||||
// 兼容图片价格档的标准字段,以及历史接口误拼写 resoluton。
|
||||
key = "resolution"
|
||||
value = strings.ToLower(strings.TrimSpace(value))
|
||||
case "videoSeconds":
|
||||
seconds, err := strconv.Atoi(value)
|
||||
if err != nil || seconds < 0 {
|
||||
@@ -200,6 +204,9 @@ func normalizeChannelModelTierSelector(capability string, input ChannelModelPric
|
||||
if _, exists := selector["vquality"]; exists && capability != "video" {
|
||||
return nil, "", 0, BadAuthRequest("只有视频模型可以按分辨率配置价格档")
|
||||
}
|
||||
if _, exists := selector["resolution"]; exists && capability != "image" {
|
||||
return nil, "", 0, BadAuthRequest("只有图片模型可以按分辨率配置价格档")
|
||||
}
|
||||
if _, exists := selector["videoSeconds"]; exists && capability != "video" {
|
||||
return nil, "", 0, BadAuthRequest("只有视频模型可以按时长配置价格档")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user