42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
// 图规模预检与幂等键归一化,供多种画布 HTTP 命令共享。
|
|
package platform
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// canvasIdempotencyKey 统一 UUID 大小写,格式合法性由具体入口继续验证。
|
|
func canvasIdempotencyKey(r *http.Request) string {
|
|
return strings.ToLower(r.Header.Get("Idempotency-Key"))
|
|
}
|
|
|
|
// canvasExceededGraphLimits 只判断节点/边/knot 数量超限;坏 JSON 返回 false 交给完整校验报告 400。
|
|
// 与 normalizeCanvas 分离,使合法可解码但规模过大的请求能明确返回 413。
|
|
func canvasExceededGraphLimits(raw json.RawMessage) bool {
|
|
var doc struct {
|
|
Nodes []json.RawMessage `json:"nodes"`
|
|
Edges []json.RawMessage `json:"edges"`
|
|
}
|
|
if json.Unmarshal(raw, &doc) != nil {
|
|
return false
|
|
}
|
|
if len(doc.Nodes) > 500 || len(doc.Edges) > 2000 {
|
|
return true
|
|
}
|
|
for _, raw := range doc.Edges {
|
|
var edge struct {
|
|
Data struct {
|
|
Path struct {
|
|
Knots []json.RawMessage `json:"knots"`
|
|
} `json:"path"`
|
|
} `json:"data"`
|
|
}
|
|
if json.Unmarshal(raw, &edge) == nil && len(edge.Data.Path.Knots) > 64 {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|