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:
+1
-1
@@ -539,7 +539,7 @@ Returns `{ "code": 0, "msg": "success", "data": { "status": "done" } }` or the c
|
|||||||
|
|
||||||
Saves canvas layout changes with a Lovart-style lightweight payload. The frontend posts to `/api/canva/project/saveProject`; `/api/projects/:id/canvas` remains as a compatibility route. The `canvas` value is a `SHAKKERDATA://` gzip+base64 encoded snapshot containing viewport, nodes, and connections. Legacy uncompressed `{ "viewport": ..., "nodes": ..., "connections": ... }` payloads are still accepted.
|
Saves canvas layout changes with a Lovart-style lightweight payload. The frontend posts to `/api/canva/project/saveProject`; `/api/projects/:id/canvas` remains as a compatibility route. The `canvas` value is a `SHAKKERDATA://` gzip+base64 encoded snapshot containing viewport, nodes, and connections. Legacy uncompressed `{ "viewport": ..., "nodes": ..., "connections": ... }` payloads are still accepted.
|
||||||
|
|
||||||
Canvas nodes may include optional `semanticContext`. CAD source nodes use `layerRole: "cad-vector"`; non-destructive crop siblings use `layerRole: "cad-crop"` and carry crop-specific context. PostgreSQL persists the field in `canvas_nodes.semantic_context`.
|
Canvas nodes may include optional `semanticContext` and `renderContent`. CAD source nodes use `layerRole: "cad-vector"`; non-destructive crop siblings use `layerRole: "cad-crop"` and carry crop-specific context. `content` remains the original SVG/CAD-derived source used by crop, download, and model-reference flows, while `renderContent` is an optional transparent WebP texture used only for fast canvas display. PostgreSQL persists both fields.
|
||||||
|
|
||||||
When a canvas image node disappears from the saved node list, its backing OSS asset is queued for asynchronous deletion after the canvas save succeeds.
|
When a canvas image node disappears from the saved node list, its backing OSS asset is queued for asynchronous deletion after the canvas save succeeds.
|
||||||
|
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ type CanvasNode {
|
|||||||
Width float64 `json:"width"`
|
Width float64 `json:"width"`
|
||||||
Height float64 `json:"height"`
|
Height float64 `json:"height"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
RenderContent string `json:"renderContent,optional"`
|
||||||
Tone string `json:"tone"`
|
Tone string `json:"tone"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
ParentId string `json:"parentId,optional"`
|
ParentId string `json:"parentId,optional"`
|
||||||
|
|||||||
@@ -189,18 +189,16 @@ func deletedCanvasAssetURLs(previous []design.Node, next []design.Node, messages
|
|||||||
seen := make(map[string]struct{})
|
seen := make(map[string]struct{})
|
||||||
var deleted []string
|
var deleted []string
|
||||||
for _, node := range previous {
|
for _, node := range previous {
|
||||||
url := nodeAssetURL(node)
|
for _, url := range nodeAssetURLs(node) {
|
||||||
if url == "" {
|
if assetURLSetContains(protectedURLs, url) {
|
||||||
continue
|
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
|
return deleted
|
||||||
}
|
}
|
||||||
@@ -220,7 +218,9 @@ func projectAssetURLs(project design.Project) []string {
|
|||||||
urls = append(urls, url)
|
urls = append(urls, url)
|
||||||
}
|
}
|
||||||
for _, node := range project.Nodes {
|
for _, node := range project.Nodes {
|
||||||
add(nodeAssetURL(node))
|
for _, url := range nodeAssetURLs(node) {
|
||||||
|
add(url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, url := range canvasSnapshotAssetURLs(project.Canvas) {
|
for _, url := range canvasSnapshotAssetURLs(project.Canvas) {
|
||||||
add(url)
|
add(url)
|
||||||
@@ -267,9 +267,7 @@ func canvasSnapshotAssetURLs(canvas string) []string {
|
|||||||
}
|
}
|
||||||
urls := make([]string, 0, len(snapshot.Nodes))
|
urls := make([]string, 0, len(snapshot.Nodes))
|
||||||
for _, node := range snapshot.Nodes {
|
for _, node := range snapshot.Nodes {
|
||||||
if url := nodeAssetURL(node); url != "" {
|
urls = append(urls, nodeAssetURLs(node)...)
|
||||||
urls = append(urls, url)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return urls
|
return urls
|
||||||
}
|
}
|
||||||
@@ -277,22 +275,26 @@ func canvasSnapshotAssetURLs(canvas string) []string {
|
|||||||
func canvasAssetURLSet(nodes []design.Node) map[string]struct{} {
|
func canvasAssetURLSet(nodes []design.Node) map[string]struct{} {
|
||||||
items := make(map[string]struct{})
|
items := make(map[string]struct{})
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if url := nodeAssetURL(node); url != "" {
|
for _, url := range nodeAssetURLs(node) {
|
||||||
addAssetURLKeys(items, url)
|
addAssetURLKeys(items, url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func nodeAssetURL(node design.Node) string {
|
func nodeAssetURLs(node design.Node) []string {
|
||||||
if node.Type != design.NodeTypeImage && node.Type != design.NodeTypeFrame {
|
if node.Type != design.NodeTypeImage && node.Type != design.NodeTypeFrame {
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
content := strings.TrimSpace(node.Content)
|
urls := make([]string, 0, 2)
|
||||||
if content == "" || strings.HasPrefix(content, "data:image/") || !isGeneratedImageContent(content) {
|
for _, content := range []string{node.Content, node.RenderContent} {
|
||||||
return ""
|
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 {
|
func promptMessageAssetURLs(content string) []string {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func TestDeleteProjectEnqueuesAssetCleanupJobWhenJobQueueIsConfigured(t *testing
|
|||||||
Status: design.StatusReady,
|
Status: design.StatusReady,
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
Nodes: []design.Node{
|
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 {
|
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)
|
t.Fatalf("expected one cleanup job, got %#v", queue.jobs)
|
||||||
}
|
}
|
||||||
job := queue.jobs[0]
|
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)
|
t.Fatalf("unexpected cleanup job: %#v", job)
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -5344,7 +5344,10 @@ func mainCanvasPreviewImage(nodes []design.Node) string {
|
|||||||
if node.Status == "generating" || node.Status == "error" || node.LayerRole == "pen-stroke" {
|
if node.Status == "generating" || node.Status == "error" || node.LayerRole == "pen-stroke" {
|
||||||
continue
|
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) {
|
if content == "" || strings.HasPrefix(content, "data:image/") || !isGeneratedImageContent(content) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type projectPreviewNode struct {
|
|||||||
Width float64 `json:"width"`
|
Width float64 `json:"width"`
|
||||||
Height float64 `json:"height"`
|
Height float64 `json:"height"`
|
||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
|
RenderContent string `json:"renderContent,omitempty"`
|
||||||
Tone string `json:"tone,omitempty"`
|
Tone string `json:"tone,omitempty"`
|
||||||
LayerRole string `json:"layerRole,omitempty"`
|
LayerRole string `json:"layerRole,omitempty"`
|
||||||
FillColor string `json:"fillColor,omitempty"`
|
FillColor string `json:"fillColor,omitempty"`
|
||||||
@@ -82,6 +83,7 @@ func canvasPreviewNodes(nodes []design.Node) []projectPreviewNode {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
content := strings.TrimSpace(node.Content)
|
content := strings.TrimSpace(node.Content)
|
||||||
|
renderContent := strings.TrimSpace(node.RenderContent)
|
||||||
if node.Type == design.NodeTypeFrame && !isGeneratedImageContent(content) {
|
if node.Type == design.NodeTypeFrame && !isGeneratedImageContent(content) {
|
||||||
content = ""
|
content = ""
|
||||||
}
|
}
|
||||||
@@ -93,6 +95,7 @@ func canvasPreviewNodes(nodes []design.Node) []projectPreviewNode {
|
|||||||
Width: math.Max(1, node.Width),
|
Width: math.Max(1, node.Width),
|
||||||
Height: math.Max(1, node.Height),
|
Height: math.Max(1, node.Height),
|
||||||
Content: content,
|
Content: content,
|
||||||
|
RenderContent: renderContent,
|
||||||
Tone: strings.TrimSpace(node.Tone),
|
Tone: strings.TrimSpace(node.Tone),
|
||||||
LayerRole: strings.TrimSpace(node.LayerRole),
|
LayerRole: strings.TrimSpace(node.LayerRole),
|
||||||
FillColor: strings.TrimSpace(node.FillColor),
|
FillColor: strings.TrimSpace(node.FillColor),
|
||||||
|
|||||||
@@ -23,13 +23,14 @@ func TestProjectThumbnailUsesCanvasPreview(t *testing.T) {
|
|||||||
Status: "success",
|
Status: "success",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "main",
|
ID: "main",
|
||||||
Type: design.NodeTypeImage,
|
Type: design.NodeTypeImage,
|
||||||
Title: "Main",
|
Title: "Main",
|
||||||
Content: "http://localhost:19000/canvas-assets/main.png",
|
Content: "http://localhost:19000/canvas-assets/main.svg",
|
||||||
Width: 1024,
|
RenderContent: "http://localhost:19000/canvas-assets/main.render.webp",
|
||||||
Height: 768,
|
Width: 1024,
|
||||||
Status: "success",
|
Height: 768,
|
||||||
|
Status: "success",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -49,7 +50,7 @@ func TestProjectThumbnailUsesCanvasPreview(t *testing.T) {
|
|||||||
if len(preview.Nodes) != 2 {
|
if len(preview.Nodes) != 2 {
|
||||||
t.Fatalf("expected two preview nodes, got %#v", preview.Nodes)
|
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])
|
t.Fatalf("expected generated image in canvas preview, got %#v", preview.Nodes[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ type Node struct {
|
|||||||
Width float64
|
Width float64
|
||||||
Height float64
|
Height float64
|
||||||
Content string
|
Content string
|
||||||
|
RenderContent string
|
||||||
Tone string
|
Tone string
|
||||||
Status string
|
Status string
|
||||||
ParentID string
|
ParentID string
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ type CanvasNode struct {
|
|||||||
FlipY bool `json:"flip_y"`
|
FlipY bool `json:"flip_y"`
|
||||||
Rotation float64 `json:"rotation"`
|
Rotation float64 `json:"rotation"`
|
||||||
SemanticContext string `json:"semantic_context"`
|
SemanticContext string `json:"semantic_context"`
|
||||||
|
RenderContent string `json:"render_content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CanvasSnapshot struct {
|
type CanvasSnapshot struct {
|
||||||
|
|||||||
@@ -467,7 +467,7 @@ func (q *Queries) ListMessagesByProject(ctx context.Context, arg ListMessagesByP
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listNodesByProject = `-- name: ListNodesByProject :many
|
const listNodesByProject = `-- name: ListNodesByProject :many
|
||||||
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context
|
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context, render_content
|
||||||
FROM canvas_nodes
|
FROM canvas_nodes
|
||||||
WHERE project_id = $1 AND user_id = $2
|
WHERE project_id = $1 AND user_id = $2
|
||||||
ORDER BY sort_order ASC, id ASC
|
ORDER BY sort_order ASC, id ASC
|
||||||
@@ -521,6 +521,7 @@ func (q *Queries) ListNodesByProject(ctx context.Context, arg ListNodesByProject
|
|||||||
&i.FlipY,
|
&i.FlipY,
|
||||||
&i.Rotation,
|
&i.Rotation,
|
||||||
&i.SemanticContext,
|
&i.SemanticContext,
|
||||||
|
&i.RenderContent,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -746,8 +747,8 @@ func (q *Queries) UpsertBrandKit(ctx context.Context, arg UpsertBrandKitParams)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const upsertCanvasNode = `-- name: UpsertCanvasNode :exec
|
const upsertCanvasNode = `-- name: UpsertCanvasNode :exec
|
||||||
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context)
|
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context, render_content)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)
|
||||||
ON CONFLICT (id) DO UPDATE SET
|
ON CONFLICT (id) DO UPDATE SET
|
||||||
project_id = EXCLUDED.project_id,
|
project_id = EXCLUDED.project_id,
|
||||||
user_id = EXCLUDED.user_id,
|
user_id = EXCLUDED.user_id,
|
||||||
@@ -780,7 +781,8 @@ ON CONFLICT (id) DO UPDATE SET
|
|||||||
flip_x = EXCLUDED.flip_x,
|
flip_x = EXCLUDED.flip_x,
|
||||||
flip_y = EXCLUDED.flip_y,
|
flip_y = EXCLUDED.flip_y,
|
||||||
rotation = EXCLUDED.rotation,
|
rotation = EXCLUDED.rotation,
|
||||||
semantic_context = EXCLUDED.semantic_context
|
semantic_context = EXCLUDED.semantic_context,
|
||||||
|
render_content = EXCLUDED.render_content
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpsertCanvasNodeParams struct {
|
type UpsertCanvasNodeParams struct {
|
||||||
@@ -817,6 +819,7 @@ type UpsertCanvasNodeParams struct {
|
|||||||
FlipY bool `json:"flip_y"`
|
FlipY bool `json:"flip_y"`
|
||||||
Rotation float64 `json:"rotation"`
|
Rotation float64 `json:"rotation"`
|
||||||
SemanticContext string `json:"semantic_context"`
|
SemanticContext string `json:"semantic_context"`
|
||||||
|
RenderContent string `json:"render_content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) UpsertCanvasNode(ctx context.Context, arg UpsertCanvasNodeParams) error {
|
func (q *Queries) UpsertCanvasNode(ctx context.Context, arg UpsertCanvasNodeParams) error {
|
||||||
@@ -854,6 +857,7 @@ func (q *Queries) UpsertCanvasNode(ctx context.Context, arg UpsertCanvasNodePara
|
|||||||
arg.FlipY,
|
arg.FlipY,
|
||||||
arg.Rotation,
|
arg.Rotation,
|
||||||
arg.SemanticContext,
|
arg.SemanticContext,
|
||||||
|
arg.RenderContent,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ func (r *ProjectRepository) Save(ctx context.Context, project design.Project) er
|
|||||||
Width: node.Width,
|
Width: node.Width,
|
||||||
Height: node.Height,
|
Height: node.Height,
|
||||||
Content: node.Content,
|
Content: node.Content,
|
||||||
|
RenderContent: node.RenderContent,
|
||||||
Tone: node.Tone,
|
Tone: node.Tone,
|
||||||
Status: node.Status,
|
Status: node.Status,
|
||||||
SortOrder: int32(index),
|
SortOrder: int32(index),
|
||||||
@@ -518,6 +519,7 @@ func mapNodes(rows []sqlcdb.CanvasNode) []design.Node {
|
|||||||
Width: row.Width,
|
Width: row.Width,
|
||||||
Height: row.Height,
|
Height: row.Height,
|
||||||
Content: row.Content,
|
Content: row.Content,
|
||||||
|
RenderContent: row.RenderContent,
|
||||||
Tone: row.Tone,
|
Tone: row.Tone,
|
||||||
Status: row.Status,
|
Status: row.Status,
|
||||||
ParentID: row.ParentID,
|
ParentID: row.ParentID,
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ SET thumbnail = $3,
|
|||||||
WHERE id = $1 AND user_id = $2;
|
WHERE id = $1 AND user_id = $2;
|
||||||
|
|
||||||
-- name: ListNodesByProject :many
|
-- name: ListNodesByProject :many
|
||||||
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context
|
SELECT id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context, render_content
|
||||||
FROM canvas_nodes
|
FROM canvas_nodes
|
||||||
WHERE project_id = $1 AND user_id = $2
|
WHERE project_id = $1 AND user_id = $2
|
||||||
ORDER BY sort_order ASC, id ASC;
|
ORDER BY sort_order ASC, id ASC;
|
||||||
@@ -124,8 +124,8 @@ DELETE FROM canvas_nodes
|
|||||||
WHERE project_id = $1 AND user_id = $2;
|
WHERE project_id = $1 AND user_id = $2;
|
||||||
|
|
||||||
-- name: UpsertCanvasNode :exec
|
-- name: UpsertCanvasNode :exec
|
||||||
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context)
|
INSERT INTO canvas_nodes (id, project_id, user_id, node_type, title, x, y, width, height, content, tone, status, sort_order, parent_id, layer_role, font_size, font_family, font_weight, color, text_align, line_height, letter_spacing, text_decoration, text_transform, opacity, fill_color, stroke_color, stroke_width, stroke_style, flip_x, flip_y, rotation, semantic_context, render_content)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)
|
||||||
ON CONFLICT (id) DO UPDATE SET
|
ON CONFLICT (id) DO UPDATE SET
|
||||||
project_id = EXCLUDED.project_id,
|
project_id = EXCLUDED.project_id,
|
||||||
user_id = EXCLUDED.user_id,
|
user_id = EXCLUDED.user_id,
|
||||||
@@ -158,7 +158,8 @@ ON CONFLICT (id) DO UPDATE SET
|
|||||||
flip_x = EXCLUDED.flip_x,
|
flip_x = EXCLUDED.flip_x,
|
||||||
flip_y = EXCLUDED.flip_y,
|
flip_y = EXCLUDED.flip_y,
|
||||||
rotation = EXCLUDED.rotation,
|
rotation = EXCLUDED.rotation,
|
||||||
semantic_context = EXCLUDED.semantic_context;
|
semantic_context = EXCLUDED.semantic_context,
|
||||||
|
render_content = EXCLUDED.render_content;
|
||||||
|
|
||||||
-- name: ListConnectionsByProject :many
|
-- name: ListConnectionsByProject :many
|
||||||
SELECT id, project_id, user_id, from_node_id, to_node_id
|
SELECT id, project_id, user_id, from_node_id, to_node_id
|
||||||
|
|||||||
@@ -195,7 +195,8 @@ CREATE TABLE IF NOT EXISTS canvas_nodes (
|
|||||||
flip_x BOOLEAN NOT NULL DEFAULT FALSE,
|
flip_x BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
flip_y BOOLEAN NOT NULL DEFAULT FALSE,
|
flip_y BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
rotation DOUBLE PRECISION NOT NULL DEFAULT 0,
|
rotation DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
semantic_context TEXT NOT NULL DEFAULT ''
|
semantic_context TEXT NOT NULL DEFAULT '',
|
||||||
|
render_content TEXT NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
|
|
||||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS user_id UUID;
|
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS user_id UUID;
|
||||||
@@ -227,6 +228,7 @@ ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS flip_x BOOLEAN NOT NULL DEFAUL
|
|||||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS flip_y BOOLEAN NOT NULL DEFAULT FALSE;
|
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS flip_y BOOLEAN NOT NULL DEFAULT FALSE;
|
||||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS rotation DOUBLE PRECISION NOT NULL DEFAULT 0;
|
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS rotation DOUBLE PRECISION NOT NULL DEFAULT 0;
|
||||||
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS semantic_context TEXT NOT NULL DEFAULT '';
|
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS semantic_context TEXT NOT NULL DEFAULT '';
|
||||||
|
ALTER TABLE canvas_nodes ADD COLUMN IF NOT EXISTS render_content TEXT NOT NULL DEFAULT '';
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS canvas_nodes_project_id_idx ON canvas_nodes(project_id);
|
CREATE INDEX IF NOT EXISTS canvas_nodes_project_id_idx ON canvas_nodes(project_id);
|
||||||
CREATE INDEX IF NOT EXISTS canvas_nodes_user_project_idx ON canvas_nodes(user_id, project_id);
|
CREATE INDEX IF NOT EXISTS canvas_nodes_user_project_idx ON canvas_nodes(user_id, project_id);
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ func TestCanvasNodeSemanticContextRoundTrip(t *testing.T) {
|
|||||||
Title: "plan.svg",
|
Title: "plan.svg",
|
||||||
LayerRole: "cad-vector",
|
LayerRole: "cad-vector",
|
||||||
SemanticContext: "CAD semantic context: layer ROOMS",
|
SemanticContext: "CAD semantic context: layer ROOMS",
|
||||||
|
RenderContent: "https://assets.example/plan-preview.webp",
|
||||||
}}
|
}}
|
||||||
|
|
||||||
roundTrip := toDomainNodes(toAPINodes(nodes))
|
roundTrip := toDomainNodes(toAPINodes(nodes))
|
||||||
if len(roundTrip) != 1 || roundTrip[0].SemanticContext != nodes[0].SemanticContext {
|
if len(roundTrip) != 1 || roundTrip[0].SemanticContext != nodes[0].SemanticContext || roundTrip[0].RenderContent != nodes[0].RenderContent {
|
||||||
t.Fatalf("expected semantic context round trip, got %#v", roundTrip)
|
t.Fatalf("expected CAD context and render content round trip, got %#v", roundTrip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ func toAPINodes(items []design.Node) []types.CanvasNode {
|
|||||||
Width: item.Width,
|
Width: item.Width,
|
||||||
Height: item.Height,
|
Height: item.Height,
|
||||||
Content: item.Content,
|
Content: item.Content,
|
||||||
|
RenderContent: item.RenderContent,
|
||||||
Tone: item.Tone,
|
Tone: item.Tone,
|
||||||
Status: item.Status,
|
Status: item.Status,
|
||||||
ParentId: item.ParentID,
|
ParentId: item.ParentID,
|
||||||
@@ -302,6 +303,7 @@ func toDomainNodes(items []types.CanvasNode) []design.Node {
|
|||||||
Width: item.Width,
|
Width: item.Width,
|
||||||
Height: item.Height,
|
Height: item.Height,
|
||||||
Content: item.Content,
|
Content: item.Content,
|
||||||
|
RenderContent: item.RenderContent,
|
||||||
Tone: item.Tone,
|
Tone: item.Tone,
|
||||||
Status: item.Status,
|
Status: item.Status,
|
||||||
ParentID: item.ParentId,
|
ParentID: item.ParentId,
|
||||||
|
|||||||
@@ -109,7 +109,11 @@ func queryProjectCoverList(project design.Project) []string {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if (node.Type == design.NodeTypeImage || node.Type == design.NodeTypeFrame) && node.Status == "success" {
|
if (node.Type == design.NodeTypeImage || node.Type == design.NodeTypeFrame) && node.Status == "success" {
|
||||||
add(node.Content)
|
if strings.TrimSpace(node.RenderContent) != "" {
|
||||||
|
add(node.RenderContent)
|
||||||
|
} else {
|
||||||
|
add(node.Content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return covers
|
return covers
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ type CanvasNode struct {
|
|||||||
Width float64 `json:"width"`
|
Width float64 `json:"width"`
|
||||||
Height float64 `json:"height"`
|
Height float64 `json:"height"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
RenderContent string `json:"renderContent,optional"`
|
||||||
Tone string `json:"tone"`
|
Tone string `json:"tone"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
ParentId string `json:"parentId,optional"`
|
ParentId string `json:"parentId,optional"`
|
||||||
|
|||||||
Reference in New Issue
Block a user