docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Canonical 读/迁移/写入口:冻结请求回执与逻辑操作去重,业务数据和回执同事务提交。
|
||||
package platform
|
||||
|
||||
import (
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
const modelMigrateAction = "model.migrate.v1"
|
||||
const modelEditAction = "model.operations.v2"
|
||||
|
||||
// newModelID 用随机字节生成 UUIDv4,随机源失败返回空值,由调用方拒绝后续处理。
|
||||
func newModelID() string {
|
||||
var value [16]byte
|
||||
if _, err := rand.Read(value[:]); err != nil {
|
||||
@@ -22,6 +24,8 @@ func newModelID() string {
|
||||
text := hex.EncodeToString(value[:])
|
||||
return text[:8] + "-" + text[8:12] + "-" + text[12:16] + "-" + text[16:20] + "-" + text[20:]
|
||||
}
|
||||
|
||||
// legacyModelRoot 沿活跃父链寻找旧树根,拒绝循环、归档和过深树。
|
||||
func legacyModelRoot(r *http.Request, tx *sql.Tx, project, workspace, board string) (string, error) {
|
||||
seen := map[string]bool{}
|
||||
for len(seen) <= 8 {
|
||||
@@ -43,6 +47,8 @@ func legacyModelRoot(r *http.Request, tx *sql.Tx, project, workspace, board stri
|
||||
}
|
||||
return "", errCanvasModel
|
||||
}
|
||||
|
||||
// collectLegacyModel 收集根下最多 256 个 board 快照及关系,限额多取一项用于检测超限。
|
||||
func collectLegacyModel(r *http.Request, tx *sql.Tx, project, workspace, root string) (map[string]canvasSnapshot, []subgraphRelation, error) {
|
||||
rows, err := tx.QueryContext(r.Context(), `WITH RECURSIVE tree(id,path) AS (SELECT $3::uuid,ARRAY[$3::uuid] UNION ALL SELECT s.child_board_id,t.path||s.child_board_id FROM tree t JOIN canvas_subgraphs s ON s.project=$1 AND s.workspace_id=$2 AND s.parent_board_id=t.id WHERE s.archived_at IS NULL AND NOT s.child_board_id=ANY(t.path) AND cardinality(t.path)<=8) SELECT m.id::text,m.canvas_version,COALESCE(m.canvas_document,'{"schema_version":2,"nodes":[],"edges":[],"viewport":{"x":0,"y":0,"zoom":1}}'::jsonb) FROM tree t JOIN materials m ON m.project=$1 AND m.workspace_id=$2 AND m.id=t.id WHERE m.kind='board' ORDER BY m.id LIMIT 257`, project, workspace, root)
|
||||
if err != nil {
|
||||
@@ -82,6 +88,8 @@ func collectLegacyModel(r *http.Request, tx *sql.Tx, project, workspace, root st
|
||||
}
|
||||
return snapshots, relations, rows.Err()
|
||||
}
|
||||
|
||||
// modelRequestRetry 按项目/工作区/账户/request ID 查冻结回执,并核对根、动作和载荷摘要防止跨用途复用。
|
||||
func modelRequestRetry(w http.ResponseWriter, r *http.Request, tx *sql.Tx, project, workspace, account, root, action, key, hash string) (bool, error) {
|
||||
var previousRoot, previousAction, previousHash string
|
||||
var status int
|
||||
@@ -100,6 +108,8 @@ func modelRequestRetry(w http.ResponseWriter, r *http.Request, tx *sql.Tx, proje
|
||||
reply(w, status, body)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// commitModelReceipt 注入协议和请求 ID,保存应用或终局拒绝回执后提交;提交成功才对外响应。
|
||||
func commitModelReceipt(w http.ResponseWriter, r *http.Request, tx *sql.Tx, project, workspace, account, root, action, key, hash string, status int, body response) error {
|
||||
body["request_id"], body["protocol_version"] = key, canvasModelProtocol
|
||||
raw, err := json.Marshal(body)
|
||||
@@ -116,6 +126,8 @@ func commitModelReceipt(w http.ResponseWriter, r *http.Request, tx *sql.Tx, proj
|
||||
reply(w, status, body)
|
||||
return nil
|
||||
}
|
||||
|
||||
// decodeModelRequest 限制五 MiB、未知字段与尾随 JSON;失败立即写出 400。
|
||||
func decodeModelRequest(w http.ResponseWriter, r *http.Request, input any) bool {
|
||||
decoder := json.NewDecoder(http.MaxBytesReader(w, r.Body, canvasLimit))
|
||||
decoder.DisallowUnknownFields()
|
||||
@@ -126,6 +138,7 @@ func decodeModelRequest(w http.ResponseWriter, r *http.Request, input any) bool
|
||||
return true
|
||||
}
|
||||
|
||||
// getCanvasModel 未迁移时返回根和源版本表;已迁移时读模型表,在发送 JSON/NDJSON 前释放锁。
|
||||
func (s *service) getCanvasModel(w http.ResponseWriter, r *http.Request, project, account string) error {
|
||||
if r.Method != http.MethodGet {
|
||||
reject(w, 405, "method_not_allowed")
|
||||
@@ -181,6 +194,7 @@ func (s *service) getCanvasModel(w http.ResponseWriter, r *http.Request, project
|
||||
return nil
|
||||
}
|
||||
|
||||
// migrateCanonicalCanvas 是显式身份屏障:完整确认旧树版本、等待在途 AI 结束,再保存模型及身份映射。
|
||||
func (s *service) migrateCanonicalCanvas(w http.ResponseWriter, r *http.Request, project, account string) error {
|
||||
if r.Method != http.MethodPost {
|
||||
reject(w, 405, "method_not_allowed")
|
||||
@@ -232,6 +246,7 @@ func (s *service) migrateCanonicalCanvas(w http.ResponseWriter, r *http.Request,
|
||||
if err != nil || done {
|
||||
return err
|
||||
}
|
||||
// 已鉴权且可冻结的业务拒绝也入回执表,同请求不能在外部条件改变后变成新的执行。
|
||||
rejectMigration := func(status int, code string) error {
|
||||
return commitModelReceipt(w, r, tx, project, workspace, account, root, modelMigrateAction, key, payloadDigest(input), status, response{"status": "not-applied", "terminal": true, "error": code})
|
||||
}
|
||||
@@ -289,6 +304,7 @@ func (s *service) migrateCanonicalCanvas(w http.ResponseWriter, r *http.Request,
|
||||
return commitModelReceipt(w, r, tx, project, workspace, account, root, modelMigrateAction, key, payloadDigest(input), 200, response{"status": "applied", "model": migration.Model.view(nil), "identity_map": migration.Identities, "source_versions": input.Expected})
|
||||
}
|
||||
|
||||
// submitCanvasModelOperations 校验预期版本与跨请求逻辑操作 ID,运行纯 reducer 后检查完整参与者和资产权限。
|
||||
func (s *service) submitCanvasModelOperations(w http.ResponseWriter, r *http.Request, project, account string) error {
|
||||
if r.Method != http.MethodPost {
|
||||
reject(w, 405, "method_not_allowed")
|
||||
@@ -339,6 +355,7 @@ func (s *service) submitCanvasModelOperations(w http.ResponseWriter, r *http.Req
|
||||
if err != nil || done {
|
||||
return err
|
||||
}
|
||||
// terminal not-applied 冻结本次确定拒绝;连接故障等未定结果返回依赖错误,由客户端同键查询/重试。
|
||||
rejectBatch := func(status int, code string) error {
|
||||
return commitModelReceipt(w, r, tx, project, workspace, account, root, modelEditAction, key, payloadDigest(input), status, response{"status": "not-applied", "terminal": true, "error": code})
|
||||
}
|
||||
@@ -351,6 +368,7 @@ func (s *service) submitCanvasModelOperations(w http.ResponseWriter, r *http.Req
|
||||
return rejectBatch(412, "version_conflict")
|
||||
}
|
||||
}
|
||||
// operation_id 独立于 request_id,防止同一逻辑编辑被换请求键再次应用。
|
||||
for _, operation := range input.Operations {
|
||||
if !uuidSlugPattern.MatchString(operation.ID) {
|
||||
return rejectBatch(400, "invalid_model_operation")
|
||||
@@ -371,6 +389,7 @@ func (s *service) submitCanvasModelOperations(w http.ResponseWriter, r *http.Req
|
||||
}
|
||||
return rejectBatch(409, code)
|
||||
}
|
||||
// reducer 识别的读写参与者都必须在 Expected 中;额外明确参与者也推进一次版本。
|
||||
for id := range touched {
|
||||
if _, exists := input.Expected[id]; !exists {
|
||||
return rejectBatch(428, "version_required")
|
||||
@@ -394,6 +413,7 @@ func (s *service) submitCanvasModelOperations(w http.ResponseWriter, r *http.Req
|
||||
after.Versions[id] = before.Versions[id] + 1
|
||||
}
|
||||
}
|
||||
// 新身份不能占用同项目其他树的元素 ID;新增或更换资产引用须按当前授权重新核对。
|
||||
for id, element := range after.Elements {
|
||||
if before.Elements[id] == nil {
|
||||
var foreign bool
|
||||
@@ -445,6 +465,8 @@ func (s *service) submitCanvasModelOperations(w http.ResponseWriter, r *http.Req
|
||||
}
|
||||
return commitModelReceipt(w, r, tx, project, workspace, account, root, modelEditAction, key, payloadDigest(input), 200, response{"status": "applied", "operation_ids": ids, "model": after.view(input.Expected)})
|
||||
}
|
||||
|
||||
// getCanvasModelOperation 当前授权后只返回本人同根冻结回执;缺记录为 unknown,不能声称确定没有执行。
|
||||
func (s *service) getCanvasModelOperation(w http.ResponseWriter, r *http.Request, project, account string) error {
|
||||
if r.Method != http.MethodGet {
|
||||
reject(w, 405, "method_not_allowed")
|
||||
@@ -490,6 +512,7 @@ func (s *service) getCanvasModelOperation(w http.ResponseWriter, r *http.Request
|
||||
return nil
|
||||
}
|
||||
|
||||
// modelExists 为其他平台流程提供是否已进入 canonical 树的轻量查询。
|
||||
func modelExists(ctx context.Context, tx *sql.Tx, project, workspace, board string) (bool, error) {
|
||||
root, err := canonicalRoot(ctx, tx, project, workspace, board)
|
||||
return root != "", err
|
||||
|
||||
Reference in New Issue
Block a user