fix: 修复6个bug并接入CodeStable工作流

Bug修复:
- GetWorkList 使用了错误的 RecordType (RecordStudy→RecordWork)
- AllRecord handler 返回错误的分页信息 (page硬编码1, pageSize用RecordsCount)
- CourseParse creditNode nil panic (加nil检查)
- WebSocket CheckOrigin 安全漏洞 (release模式限制为同源)
- math/rand 可预测 (替换为 crypto/rand)
- GetDiscussList 未实现 (补全实现, 移除重复路由)

其他:
- 接入 CodeStable 工作流体系 (codestable/ 骨架 + AGENTS.md)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 19:55:57 +08:00
parent 83ee4bb5ea
commit 2a6732ffe7
23 changed files with 1561 additions and 23 deletions

View File

@@ -1,22 +1,34 @@
package common
import (
"math/rand"
"time"
"crypto/rand"
"math/big"
)
// Rand 生成指定长度的随机字符串,字符集为 [0-9a-zA-Z]
// 使用 crypto/rand 保证不可预测性
func Rand(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
b := make([]byte, length)
max := big.NewInt(int64(len(charset)))
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
n, err := rand.Int(rand.Reader, max)
if err != nil {
// crypto/rand 不应失败,如果失败说明系统随机源有问题
panic("crypto/rand failed: " + err.Error())
}
b[i] = charset[n.Int64()]
}
return string(b)
}
// RandFloat64 返回 [0.0,1.0) 范围的随机浮点数
// 使用 crypto/rand 保证不可预测性
func RandFloat64() float64 {
return rand.Float64()
n, err := rand.Int(rand.Reader, big.NewInt(1<<53))
if err != nil {
panic("crypto/rand failed: " + err.Error())
}
return float64(n.Int64()) / float64(1<<53)
}