feat(server): persist renderContent texture and cover it in asset lifecycle
Add an optional renderContent field to canvas nodes across the go-zero API type, domain node, SQLC models/queries, PostgreSQL schema, and mappers so a lightweight transparent-WebP display texture persists alongside the original content. Prefer renderContent for project thumbnails and main-canvas previews, and treat both content and renderContent as protected/deletable asset URLs during canvas asset cleanup. Extend round-trip coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -189,18 +189,16 @@ func deletedCanvasAssetURLs(previous []design.Node, next []design.Node, messages
|
||||
seen := make(map[string]struct{})
|
||||
var deleted []string
|
||||
for _, node := range previous {
|
||||
url := nodeAssetURL(node)
|
||||
if url == "" {
|
||||
continue
|
||||
for _, url := range nodeAssetURLs(node) {
|
||||
if assetURLSetContains(protectedURLs, url) {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[url]; ok {
|
||||
continue
|
||||
}
|
||||
seen[url] = struct{}{}
|
||||
deleted = append(deleted, url)
|
||||
}
|
||||
if assetURLSetContains(protectedURLs, url) {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[url]; ok {
|
||||
continue
|
||||
}
|
||||
seen[url] = struct{}{}
|
||||
deleted = append(deleted, url)
|
||||
}
|
||||
return deleted
|
||||
}
|
||||
@@ -220,7 +218,9 @@ func projectAssetURLs(project design.Project) []string {
|
||||
urls = append(urls, url)
|
||||
}
|
||||
for _, node := range project.Nodes {
|
||||
add(nodeAssetURL(node))
|
||||
for _, url := range nodeAssetURLs(node) {
|
||||
add(url)
|
||||
}
|
||||
}
|
||||
for _, url := range canvasSnapshotAssetURLs(project.Canvas) {
|
||||
add(url)
|
||||
@@ -267,9 +267,7 @@ func canvasSnapshotAssetURLs(canvas string) []string {
|
||||
}
|
||||
urls := make([]string, 0, len(snapshot.Nodes))
|
||||
for _, node := range snapshot.Nodes {
|
||||
if url := nodeAssetURL(node); url != "" {
|
||||
urls = append(urls, url)
|
||||
}
|
||||
urls = append(urls, nodeAssetURLs(node)...)
|
||||
}
|
||||
return urls
|
||||
}
|
||||
@@ -277,22 +275,26 @@ func canvasSnapshotAssetURLs(canvas string) []string {
|
||||
func canvasAssetURLSet(nodes []design.Node) map[string]struct{} {
|
||||
items := make(map[string]struct{})
|
||||
for _, node := range nodes {
|
||||
if url := nodeAssetURL(node); url != "" {
|
||||
for _, url := range nodeAssetURLs(node) {
|
||||
addAssetURLKeys(items, url)
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func nodeAssetURL(node design.Node) string {
|
||||
func nodeAssetURLs(node design.Node) []string {
|
||||
if node.Type != design.NodeTypeImage && node.Type != design.NodeTypeFrame {
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
content := strings.TrimSpace(node.Content)
|
||||
if content == "" || strings.HasPrefix(content, "data:image/") || !isGeneratedImageContent(content) {
|
||||
return ""
|
||||
urls := make([]string, 0, 2)
|
||||
for _, content := range []string{node.Content, node.RenderContent} {
|
||||
content = strings.TrimSpace(content)
|
||||
if content == "" || strings.HasPrefix(content, "data:image/") || !isGeneratedImageContent(content) {
|
||||
continue
|
||||
}
|
||||
urls = append(urls, content)
|
||||
}
|
||||
return content
|
||||
return normalizeAssetURLs(urls)
|
||||
}
|
||||
|
||||
func promptMessageAssetURLs(content string) []string {
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestDeleteProjectEnqueuesAssetCleanupJobWhenJobQueueIsConfigured(t *testing
|
||||
Status: design.StatusReady,
|
||||
UpdatedAt: time.Now(),
|
||||
Nodes: []design.Node{
|
||||
{ID: "image-1", Type: design.NodeTypeImage, Content: "http://localhost:19000/canvas-assets/a.png", Status: "success"},
|
||||
{ID: "image-1", Type: design.NodeTypeImage, Content: "http://localhost:19000/canvas-assets/a.svg", RenderContent: "http://localhost:19000/canvas-assets/a.render.webp", Status: "success"},
|
||||
},
|
||||
}
|
||||
if err := repo.Save(ctx, project); err != nil {
|
||||
@@ -78,7 +78,7 @@ func TestDeleteProjectEnqueuesAssetCleanupJobWhenJobQueueIsConfigured(t *testing
|
||||
t.Fatalf("expected one cleanup job, got %#v", queue.jobs)
|
||||
}
|
||||
job := queue.jobs[0]
|
||||
if job.Kind != design.JobAssetCleanup || len(job.PublicURLs) != 1 || job.PublicURLs[0] != "http://localhost:19000/canvas-assets/a.png" {
|
||||
if job.Kind != design.JobAssetCleanup || len(job.PublicURLs) != 2 || job.PublicURLs[0] != "http://localhost:19000/canvas-assets/a.svg" || job.PublicURLs[1] != "http://localhost:19000/canvas-assets/a.render.webp" {
|
||||
t.Fatalf("unexpected cleanup job: %#v", job)
|
||||
}
|
||||
select {
|
||||
|
||||
@@ -5344,7 +5344,10 @@ func mainCanvasPreviewImage(nodes []design.Node) string {
|
||||
if node.Status == "generating" || node.Status == "error" || node.LayerRole == "pen-stroke" {
|
||||
continue
|
||||
}
|
||||
content := strings.TrimSpace(node.Content)
|
||||
content := strings.TrimSpace(node.RenderContent)
|
||||
if content == "" {
|
||||
content = strings.TrimSpace(node.Content)
|
||||
}
|
||||
if content == "" || strings.HasPrefix(content, "data:image/") || !isGeneratedImageContent(content) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ type projectPreviewNode struct {
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
Content string `json:"content,omitempty"`
|
||||
RenderContent string `json:"renderContent,omitempty"`
|
||||
Tone string `json:"tone,omitempty"`
|
||||
LayerRole string `json:"layerRole,omitempty"`
|
||||
FillColor string `json:"fillColor,omitempty"`
|
||||
@@ -82,6 +83,7 @@ func canvasPreviewNodes(nodes []design.Node) []projectPreviewNode {
|
||||
continue
|
||||
}
|
||||
content := strings.TrimSpace(node.Content)
|
||||
renderContent := strings.TrimSpace(node.RenderContent)
|
||||
if node.Type == design.NodeTypeFrame && !isGeneratedImageContent(content) {
|
||||
content = ""
|
||||
}
|
||||
@@ -93,6 +95,7 @@ func canvasPreviewNodes(nodes []design.Node) []projectPreviewNode {
|
||||
Width: math.Max(1, node.Width),
|
||||
Height: math.Max(1, node.Height),
|
||||
Content: content,
|
||||
RenderContent: renderContent,
|
||||
Tone: strings.TrimSpace(node.Tone),
|
||||
LayerRole: strings.TrimSpace(node.LayerRole),
|
||||
FillColor: strings.TrimSpace(node.FillColor),
|
||||
|
||||
@@ -23,13 +23,14 @@ func TestProjectThumbnailUsesCanvasPreview(t *testing.T) {
|
||||
Status: "success",
|
||||
},
|
||||
{
|
||||
ID: "main",
|
||||
Type: design.NodeTypeImage,
|
||||
Title: "Main",
|
||||
Content: "http://localhost:19000/canvas-assets/main.png",
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Status: "success",
|
||||
ID: "main",
|
||||
Type: design.NodeTypeImage,
|
||||
Title: "Main",
|
||||
Content: "http://localhost:19000/canvas-assets/main.svg",
|
||||
RenderContent: "http://localhost:19000/canvas-assets/main.render.webp",
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Status: "success",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -49,7 +50,7 @@ func TestProjectThumbnailUsesCanvasPreview(t *testing.T) {
|
||||
if len(preview.Nodes) != 2 {
|
||||
t.Fatalf("expected two preview nodes, got %#v", preview.Nodes)
|
||||
}
|
||||
if preview.Nodes[1].Content != "http://localhost:19000/canvas-assets/main.png" {
|
||||
if preview.Nodes[1].Content != "http://localhost:19000/canvas-assets/main.svg" || preview.Nodes[1].RenderContent != "http://localhost:19000/canvas-assets/main.render.webp" {
|
||||
t.Fatalf("expected generated image in canvas preview, got %#v", preview.Nodes[1])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user