docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// 素材内容 schema v1 的纯校验与规范化,不负责网络抓图或数据库存储。
|
||||
package platform
|
||||
|
||||
import (
|
||||
@@ -8,32 +9,43 @@ import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// Paragraph 与 Section 的 ID 在同一文章内共享唯一命名空间,用于稳定引用内容块。
|
||||
type Paragraph struct {
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
// Section 聚合标题、描述和有序段落;数量及总段落预算由 validArticle 检查。
|
||||
type Section struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Paragraphs []Paragraph `json:"paragraphs"`
|
||||
}
|
||||
|
||||
// Article 是有序章节容器,可为空文章,但必须有非 nil 的 Article 对象。
|
||||
type Article struct {
|
||||
Sections []Section `json:"sections"`
|
||||
}
|
||||
|
||||
// Image 仅保存 HTTPS 引用及展示信息,尺寸零值表示未提供,不在这里读取远程资源。
|
||||
type Image struct {
|
||||
URL string `json:"url"`
|
||||
Alt string `json:"alt,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
}
|
||||
|
||||
// CardPart 是带 Kind 的互斥联合,一次只能提供对应的 text/article/image 内容。
|
||||
type CardPart struct {
|
||||
Kind string `json:"kind"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
Article *Article `json:"article,omitempty"`
|
||||
Image *Image `json:"image,omitempty"`
|
||||
}
|
||||
|
||||
// Content 按素材种类使用互斥字段;board 只存 schema 标记,画布节点通过专用协议管理。
|
||||
type Content struct {
|
||||
SchemaVersion int `json:"schema_version"`
|
||||
Text *string `json:"text,omitempty"`
|
||||
@@ -44,6 +56,7 @@ type Content struct {
|
||||
|
||||
var blockID = regexp.MustCompile(`^[A-Za-z0-9_-]{1,64}$`)
|
||||
|
||||
// validArticle 限制章节、段落和文本字节数,并用一个 seen 集合拒绝章节/段落间任何重复 ID。
|
||||
func validArticle(article *Article) bool {
|
||||
if article == nil || len(article.Sections) > 200 {
|
||||
return false
|
||||
@@ -68,6 +81,8 @@ func validArticle(article *Article) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// validImage 校验 URL、替代文本及尺寸范围;拒绝用户名密码和 fragment,不执行资源可达性检查。
|
||||
func validImage(image *Image) bool {
|
||||
if image == nil || len(image.URL) > 2048 || len(image.Alt) > 2000 || image.Width < 0 || image.Width > 100000 || image.Height < 0 || image.Height > 100000 {
|
||||
return false
|
||||
@@ -75,6 +90,8 @@ func validImage(image *Image) bool {
|
||||
u, err := url.Parse(image.URL)
|
||||
return err == nil && u.Scheme == "https" && u.Hostname() != "" && u.User == nil && u.Fragment == ""
|
||||
}
|
||||
|
||||
// validPart 按判别字段检查唯一有效分支,额外的异类内容即使本身合法也会被拒绝。
|
||||
func validPart(part CardPart) bool {
|
||||
switch part.Kind {
|
||||
case "text":
|
||||
@@ -87,6 +104,8 @@ func validPart(part CardPart) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// normalizeContent 严格解码单个对象,将缺省版本补为一,并重编码为统一存储形式。
|
||||
func normalizeContent(kind string, raw json.RawMessage) (json.RawMessage, bool) {
|
||||
if raw = bytes.TrimSpace(raw); len(raw) == 0 || raw[0] != '{' {
|
||||
return nil, false
|
||||
|
||||
Reference in New Issue
Block a user