docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// 研究列表的无状态游标:保存排序锚点和查询摘要,不承担身份认证或签名校验。
|
||||
package research
|
||||
|
||||
import (
|
||||
@@ -14,6 +15,8 @@ import (
|
||||
|
||||
// Cursors locate a public corpus row, not an account or authentication token.
|
||||
// Binding to normalized filters prevents accidentally paging a different query.
|
||||
// position 的 ID 用于最近排序;标题排序还需要保留数据库原始 title_key 以稳定处理同名论文。
|
||||
// Before 指示向前翻页,Filter 将游标限定在同一筛选条件和页大小内。
|
||||
type position struct {
|
||||
Version int `json:"v"`
|
||||
ID int64 `json:"id"`
|
||||
@@ -24,6 +27,7 @@ type position struct {
|
||||
|
||||
var errCursor = errors.New("invalid cursor")
|
||||
|
||||
// filterKey 在游标生成与读取两端统一缺省值,把查询条件编码为固定长度摘要。
|
||||
func filterKey(f Filters) string {
|
||||
sort, search := f.Sort, f.SearchIn
|
||||
if sort == "" {
|
||||
@@ -36,6 +40,8 @@ func filterKey(f Filters) string {
|
||||
sum := sha256.Sum256(data)
|
||||
return hex.EncodeToString(sum[:16])
|
||||
}
|
||||
|
||||
// encodeCursor 复制锚点并写协议版本、翻页方向;非标题排序删除无用 Key,缩小 URL。
|
||||
func encodeCursor(f Filters, p position, before bool) string {
|
||||
p.Version, p.Before, p.Filter = 1, before, filterKey(f)
|
||||
if f.Sort != "title" {
|
||||
@@ -44,6 +50,8 @@ func encodeCursor(f Filters, p position, before bool) string {
|
||||
data, _ := json.Marshal(p)
|
||||
return base64.RawURLEncoding.EncodeToString(data)
|
||||
}
|
||||
|
||||
// decodeCursor 将空值视为首页;拒绝过长、额外字段、多 JSON 值或与当前筛选不符的游标。
|
||||
func decodeCursor(f Filters) (position, error) {
|
||||
var p position
|
||||
if f.Cursor == "" {
|
||||
|
||||
Reference in New Issue
Block a user