Files
cluster/pkg/tool/mask.go
loveuer 9780a2b028 feat: add registry config, image upload/download, and OCI format support
Backend:
- Add registry_address configuration API (GET/POST)
- Add tar image upload with OCI and Docker format support
- Add image download with streaming optimization
- Fix blob download using c.Send (Fiber v3 SendStream bug)
- Add registry_address prefix stripping for all OCI v2 endpoints
- Add AGENTS.md for project documentation

Frontend:
- Add settings store with Snackbar notifications
- Add image upload dialog with progress bar
- Add download state tracking with multi-stage feedback
- Replace alert() with MUI Snackbar messages
- Display image names without registry_address prefix

🤖 Generated with [Qoder](https://qoder.com)
2025-11-10 16:28:58 +08:00

58 lines
1.1 KiB
Go

package tool
import (
"strings"
)
func MaskJWT(token string) string {
if token == "" {
return ""
}
parts := strings.Split(token, ".")
if len(parts) != 3 {
return MaskString(token, 5, 5, -1, "*")
}
h, p, s := parts[0], parts[1], parts[2]
h, p, s = MaskString(h, 5, 5, 8, "*"), MaskString(p, 5, 5, 8, "*"), MaskString(s, 5, 5, 8, "*")
return h + "." + p + "." + s
}
// MaskString 将字符串中间部分替换为 maskChar
//
// start: 保留前 start 个字符
// end: 保留后 end 个字符
// maskLen: 中间打码长度 (小于 0 标识保持原有长度)
// maskChar: 打码字符
func MaskString(s string, start, end, maskLen int, maskChar string) string {
if s == "" {
return ""
}
totalLen := len(s)
if start < 0 {
start = 0
}
if end < 0 {
end = 0
}
if maskChar == "" {
maskChar = "*"
}
maxMaskLen := totalLen - start - end
if maxMaskLen <= 0 {
return strings.Repeat(maskChar, totalLen)
}
if maskLen < 0 || maskLen > maxMaskLen {
maskLen = maxMaskLen
}
startPart, endPart := s[:start], s[totalLen-end:]
return startPart + strings.Repeat(maskChar, maskLen) + endPart
}