fix: sync WebK compatibility paths

This commit is contained in:
A 2026-07-15 16:07:43 +08:00
parent 766c5db992
commit 76bfc5100f
12 changed files with 387 additions and 8 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"regexp"
"strings"
"unicode/utf8"
"github.com/iamxvbaba/td/tg"
)
@ -35,6 +36,11 @@ func inboundRPCBytesFrom(ctx context.Context) int {
const currentClientLayer = tg.Layer
const (
maxClientDeviceModelRunes = 128
maxClientMetadataRunes = 64
)
var androidSDKVersionRE = regexp.MustCompile(`\bsdk\s+\d+\b`)
type ClientType string
@ -98,11 +104,33 @@ func ClientTypeFrom(ctx context.Context) ClientType {
}
func normalizeClientInfo(info ClientInfo) ClientInfo {
// Classify against the complete wire metadata before bounding the values
// shared by auth-key and authorization persistence.
info.Type = detectClientType(info)
info.DeviceModel = truncateClientMetadata(info.DeviceModel, maxClientDeviceModelRunes)
info.SystemVersion = truncateClientMetadata(info.SystemVersion, maxClientMetadataRunes)
info.AppVersion = truncateClientMetadata(info.AppVersion, maxClientMetadataRunes)
info.SystemLangCode = truncateClientMetadata(info.SystemLangCode, maxClientMetadataRunes)
info.LangPack = truncateClientMetadata(info.LangPack, maxClientMetadataRunes)
info.LangCode = truncateClientMetadata(info.LangCode, maxClientMetadataRunes)
info.typeResolved = true
return info
}
func truncateClientMetadata(value string, maxRunes int) string {
if maxRunes <= 0 || value == "" {
return ""
}
if utf8.ValidString(value) && utf8.RuneCountInString(value) <= maxRunes {
return value
}
runes := []rune(value)
if len(runes) > maxRunes {
runes = runes[:maxRunes]
}
return string(runes)
}
func (info ClientInfo) ClientType() ClientType {
if info.typeResolved {
if knownClientType(info.Type) {