完善初始化更新

This commit is contained in:
2026-03-20 20:42:33 +08:00
parent 568ccb08fa
commit e6866feb29
39 changed files with 6986 additions and 2379 deletions

View File

@@ -0,0 +1,40 @@
package models
import (
"regexp"
"strings"
)
const (
MaxAuthClientIDLen = 64
MaxAuthClientNameLen = 128
)
var authClientIDRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,63}$`)
// AuthClientEntry 记录某第三方应用曾用本账号完成认证(登录 / 校验令牌 / 拉取 me
type AuthClientEntry struct {
ClientID string `json:"clientId"`
DisplayName string `json:"displayName,omitempty"`
FirstSeenAt string `json:"firstSeenAt"`
LastSeenAt string `json:"lastSeenAt"`
}
func NormalizeAuthClientID(raw string) (string, bool) {
s := strings.TrimSpace(raw)
if s == "" || len(s) > MaxAuthClientIDLen {
return "", false
}
if !authClientIDRe.MatchString(s) {
return "", false
}
return s, true
}
func ClampAuthClientName(raw string) string {
s := strings.TrimSpace(raw)
if len(s) > MaxAuthClientNameLen {
return s[:MaxAuthClientNameLen]
}
return s
}