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:
2026-07-16 20:45:56 +08:00
parent e7a0cc0b86
commit ee2c52bbc6
17 changed files with 75 additions and 46 deletions
@@ -105,6 +105,7 @@ type CanvasNode struct {
FlipY bool `json:"flip_y"`
Rotation float64 `json:"rotation"`
SemanticContext string `json:"semantic_context"`
RenderContent string `json:"render_content"`
}
type CanvasSnapshot struct {
@@ -467,7 +467,7 @@ func (q *Queries) ListMessagesByProject(ctx context.Context, arg ListMessagesByP
}
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
WHERE project_id = $1 AND user_id = $2
ORDER BY sort_order ASC, id ASC
@@ -521,6 +521,7 @@ func (q *Queries) ListNodesByProject(ctx context.Context, arg ListNodesByProject
&i.FlipY,
&i.Rotation,
&i.SemanticContext,
&i.RenderContent,
); err != nil {
return nil, err
}
@@ -746,8 +747,8 @@ func (q *Queries) UpsertBrandKit(ctx context.Context, arg UpsertBrandKitParams)
}
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)
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)
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, $34)
ON CONFLICT (id) DO UPDATE SET
project_id = EXCLUDED.project_id,
user_id = EXCLUDED.user_id,
@@ -780,7 +781,8 @@ ON CONFLICT (id) DO UPDATE SET
flip_x = EXCLUDED.flip_x,
flip_y = EXCLUDED.flip_y,
rotation = EXCLUDED.rotation,
semantic_context = EXCLUDED.semantic_context
semantic_context = EXCLUDED.semantic_context,
render_content = EXCLUDED.render_content
`
type UpsertCanvasNodeParams struct {
@@ -817,6 +819,7 @@ type UpsertCanvasNodeParams struct {
FlipY bool `json:"flip_y"`
Rotation float64 `json:"rotation"`
SemanticContext string `json:"semantic_context"`
RenderContent string `json:"render_content"`
}
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.Rotation,
arg.SemanticContext,
arg.RenderContent,
)
return err
}
@@ -199,6 +199,7 @@ func (r *ProjectRepository) Save(ctx context.Context, project design.Project) er
Width: node.Width,
Height: node.Height,
Content: node.Content,
RenderContent: node.RenderContent,
Tone: node.Tone,
Status: node.Status,
SortOrder: int32(index),
@@ -518,6 +519,7 @@ func mapNodes(rows []sqlcdb.CanvasNode) []design.Node {
Width: row.Width,
Height: row.Height,
Content: row.Content,
RenderContent: row.RenderContent,
Tone: row.Tone,
Status: row.Status,
ParentID: row.ParentID,
@@ -114,7 +114,7 @@ SET thumbnail = $3,
WHERE id = $1 AND user_id = $2;
-- 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
WHERE project_id = $1 AND user_id = $2
ORDER BY sort_order ASC, id ASC;
@@ -124,8 +124,8 @@ DELETE FROM canvas_nodes
WHERE project_id = $1 AND user_id = $2;
-- 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)
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)
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, $34)
ON CONFLICT (id) DO UPDATE SET
project_id = EXCLUDED.project_id,
user_id = EXCLUDED.user_id,
@@ -158,7 +158,8 @@ ON CONFLICT (id) DO UPDATE SET
flip_x = EXCLUDED.flip_x,
flip_y = EXCLUDED.flip_y,
rotation = EXCLUDED.rotation,
semantic_context = EXCLUDED.semantic_context;
semantic_context = EXCLUDED.semantic_context,
render_content = EXCLUDED.render_content;
-- name: ListConnectionsByProject :many
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_y BOOLEAN NOT NULL DEFAULT FALSE,
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;
@@ -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 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 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_user_project_idx ON canvas_nodes(user_id, project_id);