docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]

This commit is contained in:
2026-11-16 17:52:11 +08:00
parent 30829eeb86
commit 1090591503
123 changed files with 1279 additions and 3 deletions
+12
View File
@@ -1,3 +1,4 @@
// 邀请链接分离公开点击与登录后兑换:点击只记录来源,兑换才增加角色和使用次数。
package platform
import (
@@ -14,17 +15,21 @@ import (
var linkTokenPattern = regexp.MustCompile(`^[A-Za-z0-9_-]{22}$`)
// newLinkToken 产生十六随机字节的公开邀请凭据及落库摘要;明文仅在创建响应中给出。
func newLinkToken() (string, string) {
var raw [16]byte
rand.Read(raw[:])
value := base64.RawURLEncoding.EncodeToString(raw[:])
return value, linkDigest(value)
}
// linkDigest 与 newLinkToken/shortLink/redeemShare 共用相同摘要格式,数据库不保存邀请明文。
func linkDigest(token string) string {
sum := sha256.Sum256([]byte(token))
return base64.RawURLEncoding.EncodeToString(sum[:])
}
// shareInput 可邀请加入整个工作区或单个素材;单素材不能授予 admin,缺省有效期七天。
type shareInput struct {
Role string `json:"role"`
MaterialID *string `json:"material_id"`
@@ -32,6 +37,7 @@ type shareInput struct {
MaxUses *int `json:"max_uses"`
}
// shares 仅供工作区 admin 列表或创建邀请;列表返回统计和链接 ID,不可还原原始 token。
func (s *service) shares(w http.ResponseWriter, r *http.Request, project, account string) error {
workspace := r.PathValue("workspace")
if r.Method != http.MethodPost && r.Method != http.MethodGet {
@@ -110,6 +116,7 @@ VALUES($1,$2,$3,$4,$5,$6,now()+$7*interval '1 second',$8) RETURNING id::text,exp
return nil
}
// revokeShare 设置首次撤销时间,重复撤销保留时间;只阻止未来兑换,不回收已授予角色。
func (s *service) revokeShare(w http.ResponseWriter, r *http.Request, project, account string) error {
if r.Method != http.MethodDelete {
reject(w, 405, "method_not_allowed")
@@ -150,6 +157,7 @@ UPDATE share_links SET revoked_at=COALESCE(revoked_at,now()) WHERE project=$1 AN
// A public short link records only a referring origin and redirects to a fixed
// frontend. The fragment carries the invitation, never a login session.
// shortLink 是无需会话的公开入口,只记录 Referer 的 origin,邀请 token 放入固定前端回调 fragment。
func (s *service) shortLink(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Referrer-Policy", "no-referrer")
@@ -202,6 +210,7 @@ SELECT project FROM click
http.Redirect(w, r, destination.String(), 302)
}
// redeemShare 按工作区再链接的顺序加锁,原子校验有效期、容量与既往兑换记录。
func (s *service) redeemShare(w http.ResponseWriter, r *http.Request, project, account string) error {
if r.Method != http.MethodPost {
reject(w, 405, "method_not_allowed")
@@ -243,6 +252,7 @@ FROM share_links WHERE project=$1 AND workspace_id=$2 AND token_hash=$3 FOR UPDA
if err != nil {
return err
}
// 已兑换者可在容量耗尽后重复读取结果,但链接过期或撤销后仍不可兑换。
if !allowed || (!capacity && !redeemed) {
reject(w, 410, "share_unavailable")
return nil
@@ -257,6 +267,7 @@ INSERT INTO share_redemptions(project,workspace_id,link_id,account_id) VALUES($1
if err != nil {
return err
}
// 唯一兑换记录插入成功才提升角色并计数;重复请求不重复消耗额度,也不降低原有更高角色。
if n > 0 {
if material == nil {
_, err = tx.ExecContext(r.Context(), `
@@ -287,6 +298,7 @@ ON CONFLICT(project,workspace_id,material_id,account_id) DO UPDATE SET role=CASE
return nil
}
// shareClicks 仅 admin 可读,按递减点击 ID 做游标分页,多取一条判断 next_before。
func (s *service) shareClicks(w http.ResponseWriter, r *http.Request, project, account string) error {
if r.Method != http.MethodGet {
reject(w, 405, "method_not_allowed")