fix: 修复前端无法加载七牛云图片的问题
1. 修复 buildURL 中 url.PathEscape 对路径分隔符 / 的错误编码(/→%2F), 改为逐段编码后拼接 2. AssetResponse 新增 key 字段,返回七牛云对象存储 Key 3. 前端改用 /api/v1/assets/download 接口加载图片,通过后端 302 重定向 访问 CDN,避免浏览器直接访问 CDN 可能出现的跨域或编码问题 4. 更新 api.md 文档,补充 key 字段说明和 download 接口公开属性
This commit is contained in:
@@ -36,6 +36,7 @@ type GenerateResponse struct {
|
||||
|
||||
// AssetResponse 单个素材响应。
|
||||
type AssetResponse struct {
|
||||
Key string `json:"key"`
|
||||
URL string `json:"url"`
|
||||
Format string `json:"format"`
|
||||
}
|
||||
@@ -156,6 +157,7 @@ func runPipelineBg(projectID, taskID string, req GenerateRequest) {
|
||||
return
|
||||
}
|
||||
assets[i] = AssetResponse{
|
||||
Key: key,
|
||||
URL: cdnURL,
|
||||
Format: a.Format,
|
||||
}
|
||||
|
||||
@@ -94,5 +94,9 @@ func (s *StorageService) Delete(ctx context.Context, key string) error {
|
||||
// buildURL 根据配置构建完整的 CDN URL。
|
||||
func (s *StorageService) buildURL(key string) string {
|
||||
host := strings.TrimRight(s.cfg.CDNHost, "/")
|
||||
return fmt.Sprintf("%s/%s", host, url.PathEscape(key))
|
||||
segments := strings.Split(key, "/")
|
||||
for i, seg := range segments {
|
||||
segments[i] = url.PathEscape(seg)
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", host, strings.Join(segments, "/"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user