fix(*): 质量检查 - 修复预演保存、增量同步与缺失资源恢复
This commit is contained in:
1 parent
298bee1fa9
commit
27c8066e6d
20 files changed
+257
-71
No files matched your search
@@ -219,17 +219,7 @@ func TestRepriceTierFieldValidation(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)
|
||||
}
|
||||
}
|
||||
func TestBatchRepricingRollsBackOnConcurrentChange(t *testing.T) {
|
||||
for _, target := range []string{"model", "tier"} {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
svc, db, _ := seedRepricingModels(t)
|
||||
@@ -265,3 +255,15 @@ func TestNormalizeChannelModelTierSelectorAcceptsResolutionTypo(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)
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func TestChannelPresentationUsesModelLabelsAndPublicOrder(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(catalog) != 2 || catalog[0].ID != "second" || catalog[0].Name != "渠道second" || catalog[0].DisplayName != "渠道second" {
|
||||
if len(catalog) != 2 || catalog[0].ID != "second" || catalog[0].Name != "" || catalog[0].DisplayName != "" {
|
||||
t.Fatalf("public catalog: %#v", catalog)
|
||||
}
|
||||
legacy, err := svc.PublicSystemChannels()
|
||||
@@ -74,7 +74,7 @@ func TestChannelPresentationUsesModelLabelsAndPublicOrder(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog, err = svc.publicSystemChannelCatalog(nil)
|
||||
if err != nil || catalog[0].Name != "渠道second" {
|
||||
if err != nil || catalog[0].Name != "" || catalog[0].DisplayName != "" {
|
||||
t.Fatalf("channel name: %v %v", catalog, err)
|
||||
}
|
||||
for _, invalid := range []int{-1, 1000000} {
|
||||
|
||||
@@ -169,10 +169,12 @@ func (s *Service) publicSystemChannelCatalog(intent *ModelRequestIntent) ([]Publ
|
||||
}
|
||||
|
||||
if len(publicModels) > 0 {
|
||||
// 系统渠道的真实名称属于内部部署信息(供应商、中转站、内部命名等),
|
||||
// 不得通过普通用户可访问的创作目录泄漏。前端只依赖 ID 做分组,名称留空后由客户端统一展示为“系统模型”。
|
||||
result = append(result, PublicChannelCatalog{
|
||||
ID: channel.ID,
|
||||
Name: channel.Name,
|
||||
DisplayName: channel.Name,
|
||||
Name: "",
|
||||
DisplayName: "",
|
||||
SortOrder: channel.SortOrder,
|
||||
Models: publicModels,
|
||||
})
|
||||
|
||||
@@ -6,8 +6,10 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
@@ -182,22 +184,30 @@ func downloadRemoteResource(rawURL string, maxBytes int64) (remoteResourcePayloa
|
||||
if err != nil {
|
||||
return remoteResourcePayload{}, err
|
||||
}
|
||||
client := OutboundHTTPClient(90 * time.Second)
|
||||
client := OutboundHTTPClient(3 * time.Minute)
|
||||
req, err := http.NewRequest(http.MethodGet, parsed.String(), nil)
|
||||
if err != nil {
|
||||
return remoteResourcePayload{}, err
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return remoteResourcePayload{}, err
|
||||
// 把下载层网络错误统一映射为可公开的 502/504 文案,避免在恢复接口上被 failService
|
||||
// 折叠成通用的“系统处理失败”。同时保留真实原因在 Cause 里供诊断日志追踪。
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
return remoteResourcePayload{}, WrapAppError(http.StatusGatewayTimeout, "远程资源下载超时,请检查地址是否可访问或稍后重试", err)
|
||||
}
|
||||
return remoteResourcePayload{}, WrapAppError(http.StatusBadGateway, "远程资源下载失败,请检查地址是否可访问", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return remoteResourcePayload{}, fmt.Errorf("远程资源下载失败:%s", resp.Status)
|
||||
return remoteResourcePayload{}, WrapAppError(http.StatusBadGateway, fmt.Sprintf("远程资源下载失败:%s", resp.Status), nil)
|
||||
}
|
||||
data, err := io.ReadAll(io.LimitReader(resp.Body, maxBytes))
|
||||
if err != nil {
|
||||
return remoteResourcePayload{}, err
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
return remoteResourcePayload{}, WrapAppError(http.StatusGatewayTimeout, "远程资源下载超时,请检查地址是否可访问或稍后重试", err)
|
||||
}
|
||||
return remoteResourcePayload{}, WrapAppError(http.StatusBadGateway, "远程资源读取失败,请检查地址是否可访问", err)
|
||||
}
|
||||
if int64(len(data)) >= maxBytes {
|
||||
return remoteResourcePayload{}, BadAuthRequest(fmt.Sprintf("远程资源必须小于 %s", formatStorageLimit(maxBytes)))
|
||||
|
||||
Reference in new issue
Block a user