fix(assets): 复用生成素材身份并保留空缓存同步前的编辑 (#690)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
67e2e1ebbf
commit
544daa4b9f
11 files changed
+798
-14
No files matched your search
@@ -61,6 +61,11 @@ func (s *Service) AudioOutputDurationMs(task model.Task) (int64, error) {
|
||||
return resource.DurationMs, nil
|
||||
}
|
||||
|
||||
func generationMediaAssetID(taskID string, index int) string {
|
||||
sum := sha256.Sum256([]byte(fmt.Sprintf("materialize:%s:%d", taskID, index)))
|
||||
return "generation_" + hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
// Uses the same effect key and ID as browser materialization, so reconnecting
|
||||
// the canvas cannot create a second asset for a server-delivered output.
|
||||
func (s *Service) registerRecoveredMediaAssets(task model.Task) error {
|
||||
@@ -99,8 +104,7 @@ func (s *Service) registerRecoveredMediaAssets(task model.Task) error {
|
||||
return errors.New("作品文件尚未保存完成")
|
||||
}
|
||||
effectKey := fmt.Sprintf("materialize:%s:%d", task.ID, index)
|
||||
sum := sha256.Sum256([]byte(effectKey))
|
||||
assetID := "generation_" + hex.EncodeToString(sum[:])
|
||||
assetID := generationMediaAssetID(task.ID, index)
|
||||
// Preserve existing user edits on replay; the deterministic key is unique.
|
||||
if _, err := s.repo.AssetForUser(task.UserID, assetID); err == nil {
|
||||
continue
|
||||
@@ -115,12 +119,12 @@ func (s *Service) registerRecoveredMediaAssets(task model.Task) error {
|
||||
} else {
|
||||
data["url"] = url
|
||||
}
|
||||
title := "生成作品"
|
||||
title := map[string]string{"image": "生成图片", "video": "生成视频", "audio": "生成音频"}[checkpoint.Mode]
|
||||
metadata := map[string]any{"source": "generation-task", "generationEffectKey": effectKey, "taskId": task.ID, "outputIndex": index}
|
||||
if projectID != "" {
|
||||
metadata["projectIds"] = []string{projectID}
|
||||
}
|
||||
payload, err := json.Marshal(map[string]any{"id": assetID, "kind": checkpoint.Mode, "category": model.AssetCategoryMaterial, "status": model.AssetVersionStatusConfirmed, "title": title, "coverUrl": url, "tags": []string{"生成"}, "createdAt": now.UTC().Format(time.RFC3339Nano), "updatedAt": now.UTC().Format(time.RFC3339Nano), "data": data, "metadata": metadata})
|
||||
payload, err := json.Marshal(map[string]any{"id": assetID, "kind": checkpoint.Mode, "category": model.AssetCategoryMaterial, "status": model.AssetVersionStatusConfirmed, "source": "生成任务", "title": title, "coverUrl": url, "tags": []string{"生成"}, "createdAt": now.UTC().Format(time.RFC3339Nano), "updatedAt": now.UTC().Format(time.RFC3339Nano), "data": data, "metadata": metadata})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user