fix: sync collectible document role validation

Sync telesrv d8ad5cc (fix(stargifts): validate collectible document roles).

Skipped telesrv docs changes per public sync rules.
This commit is contained in:
A 2026-07-20 16:50:05 +08:00
parent 2848ff0987
commit ba82fbccd6
9 changed files with 319 additions and 7 deletions

View file

@ -981,7 +981,8 @@ func validateStarGiftAttributes(attributes []StarGiftCollectibleAttribute, kind
len(attribute.Animation.TGS) == 0 || len(attribute.Animation.SHA256) != 32 {
return ErrStarGiftCollectibleInvalid
}
if requireStoredAsset && (attribute.Document == nil || !attribute.Document.IsSticker() ||
if requireStoredAsset && (attribute.Document == nil ||
!validStarGiftCollectibleDocument(*attribute.Document, kind) ||
attribute.Document.MimeType != "application/x-tgsticker" || attribute.Blob == nil) {
return ErrStarGiftCollectibleInvalid
}
@ -1003,6 +1004,38 @@ func validateStarGiftAttributes(attributes []StarGiftCollectibleAttribute, kind
return nil
}
// validStarGiftCollectibleDocument enforces the client-visible document roles
// materialized by the Star Gift write boundary. Models are ordinary stickers.
// Patterns are text-color custom emoji with an inline PhotoPathSize so Android
// can classify and tint the TGS before its full first frame is downloaded.
func validStarGiftCollectibleDocument(document Document, kind StarGiftCollectibleAttributeKind) bool {
renderAttributes := 0
validRenderAttribute := false
for _, attribute := range document.Attributes {
switch attribute.Kind {
case DocAttrSticker:
renderAttributes++
validRenderAttribute = validRenderAttribute || kind == StarGiftCollectibleModel
case DocAttrCustomEmoji:
renderAttributes++
validRenderAttribute = validRenderAttribute ||
(kind == StarGiftCollectiblePattern && attribute.TextColor)
}
}
if renderAttributes != 1 || !validRenderAttribute {
return false
}
if kind == StarGiftCollectibleModel {
return true
}
for _, thumb := range document.Thumbs {
if thumb.Kind == PhotoSizeKindPath && strings.TrimSpace(thumb.Type) != "" && len(thumb.Bytes) > 0 {
return true
}
}
return false
}
// StarGiftCatalogHash 由客户端可见目录字段折叠出稳定 hash,供 getStarGifts NotModified。
func StarGiftCatalogHash(catalog []StarGift) int {
var h uint64