branding for server
This commit is contained in:
parent
d70148aca3
commit
a336c99d6d
6 changed files with 89 additions and 3 deletions
|
|
@ -443,6 +443,11 @@ func run(logger *zap.Logger) error {
|
||||||
zap.Int("blobs", stats.Blobs),
|
zap.Int("blobs", stats.Blobs),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if seeded, err := filesService.SeedOfficialSystemAvatar(ctx); err != nil {
|
||||||
|
return fmt.Errorf("seed official system avatar: %w", err)
|
||||||
|
} else if seeded {
|
||||||
|
logger.Info("官方系统账号头像种子导入完成", zap.Int64("photo_id", domain.OfficialSystemUserPhotoID))
|
||||||
|
}
|
||||||
if stats, err := filesService.WarmCaches(ctx); err != nil {
|
if stats, err := filesService.WarmCaches(ctx); err != nil {
|
||||||
logger.Warn("媒体资源缓存预热失败", zap.Error(err))
|
logger.Warn("媒体资源缓存预热失败", zap.Error(err))
|
||||||
} else if stats.StickerSets > 0 || stats.Documents > 0 || stats.Blobs > 0 {
|
} else if stats.StickerSets > 0 || stats.Documents > 0 || stats.Blobs > 0 {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
UPDATE public.users
|
||||||
|
SET first_name = 'Telegram', username = 'telegram', updated_at = now()
|
||||||
|
WHERE id = 777000;
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
-- Rebrand the built-in official system account (777000) from the upstream
|
||||||
|
-- gramsrv default "Telegram"/@telegram to this fork's own identity. Existing
|
||||||
|
-- databases already seeded by migration 0001 need this as a follow-up
|
||||||
|
-- UPDATE; migration 0001 itself is never replayed on an already-migrated
|
||||||
|
-- database.
|
||||||
|
UPDATE public.users
|
||||||
|
SET first_name = 'OwpenGram', username = 'owpengram', updated_at = now()
|
||||||
|
WHERE id = 777000;
|
||||||
BIN
internal/app/files/seedassets/owpengram_system_avatar.png
Normal file
BIN
internal/app/files/seedassets/owpengram_system_avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
44
internal/app/files/system_avatar_seed.go
Normal file
44
internal/app/files/system_avatar_seed.go
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
package files
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
_ "embed"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"telesrv/internal/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed seedassets/owpengram_system_avatar.png
|
||||||
|
var officialSystemAvatarPNG []byte
|
||||||
|
|
||||||
|
// SeedOfficialSystemAvatar idempotently seeds the built-in official system
|
||||||
|
// account's (777000) profile photo from the bundled brand logo, writing it
|
||||||
|
// under the fixed domain.OfficialSystemUserPhotoID so the photo/blob layer
|
||||||
|
// and the pure domain.OfficialSystemUser() struct literal stay in sync
|
||||||
|
// across restarts. Returns true if it actually wrote a new photo.
|
||||||
|
func (s *Service) SeedOfficialSystemAvatar(ctx context.Context) (bool, error) {
|
||||||
|
photoID := domain.OfficialSystemUserPhotoID
|
||||||
|
if existing, found, err := s.media.GetPhoto(ctx, photoID); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else if found {
|
||||||
|
domain.SetOfficialSystemUserAvatar(existing.DCID, domain.StrippedFromSizes(existing.Sizes))
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
sizes, err := s.putPhotoStaticSizes(ctx, photoID, officialSystemAvatarPNG, photoSizeSpecsForAvatar(officialSystemAvatarPNG))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
photo := domain.Photo{
|
||||||
|
ID: photoID,
|
||||||
|
AccessHash: domain.OfficialSystemUserPhotoAccessHash,
|
||||||
|
FileReference: randomFileReference(),
|
||||||
|
Date: int(time.Now().Unix()),
|
||||||
|
DCID: s.dc,
|
||||||
|
Sizes: sizes,
|
||||||
|
}
|
||||||
|
if err := s.media.PutPhoto(ctx, photo); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
domain.SetOfficialSystemUserAvatar(photo.DCID, domain.StrippedFromSizes(photo.Sizes))
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,11 @@ package domain
|
||||||
const (
|
const (
|
||||||
// OfficialSystemUserID 是 Telegram 兼容客户端识别的官方系统账号。
|
// OfficialSystemUserID 是 Telegram 兼容客户端识别的官方系统账号。
|
||||||
OfficialSystemUserID int64 = 777000
|
OfficialSystemUserID int64 = 777000
|
||||||
|
// OfficialSystemUserPhotoID/AccessHash 是该账号头像 photo 的固定 id,
|
||||||
|
// 与 files.Service.SeedOfficialSystemAvatar 种子写入的行保持一致,
|
||||||
|
// 确保跨重启后 OfficialSystemUser() 引用的 photo id 稳定不变。
|
||||||
|
OfficialSystemUserPhotoID int64 = 7770000001
|
||||||
|
OfficialSystemUserPhotoAccessHash int64 = 5837219004471160321
|
||||||
|
|
||||||
// BotFatherUserID 是内置 BotFather 账号,与官方 @BotFather 同 ID。
|
// BotFatherUserID 是内置 BotFather 账号,与官方 @BotFather 同 ID。
|
||||||
BotFatherUserID int64 = 93372553
|
BotFatherUserID int64 = 93372553
|
||||||
|
|
@ -21,17 +26,38 @@ const (
|
||||||
ChatBotAccessHash int64 = 6332902371644871201
|
ChatBotAccessHash int64 = 6332902371644871201
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// officialSystemUserPhotoDCID/Stripped 由 files.Service.SeedOfficialSystemAvatar
|
||||||
|
// 在启动时通过 SetOfficialSystemUserAvatar 写入一次;写入前 OfficialSystemUser()
|
||||||
|
// 不带头像(PhotoID==0),与其它未设置头像的账号行为一致。
|
||||||
|
var (
|
||||||
|
officialSystemUserPhotoDCID int
|
||||||
|
officialSystemUserPhotoStripped []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetOfficialSystemUserAvatar 记录官方系统账号头像所在的 DC 与内联缩略图字节。
|
||||||
|
// 只应在启动阶段、头像 seed 完成后调用一次。
|
||||||
|
func SetOfficialSystemUserAvatar(dcID int, stripped []byte) {
|
||||||
|
officialSystemUserPhotoDCID = dcID
|
||||||
|
officialSystemUserPhotoStripped = stripped
|
||||||
|
}
|
||||||
|
|
||||||
// OfficialSystemUser 返回第一阶段内置的官方系统账号。
|
// OfficialSystemUser 返回第一阶段内置的官方系统账号。
|
||||||
func OfficialSystemUser() User {
|
func OfficialSystemUser() User {
|
||||||
return User{
|
u := User{
|
||||||
ID: OfficialSystemUserID,
|
ID: OfficialSystemUserID,
|
||||||
AccessHash: 6599886787491911851,
|
AccessHash: 6599886787491911851,
|
||||||
Phone: "42777",
|
Phone: "42777",
|
||||||
FirstName: "Telegram",
|
FirstName: "OwpenGram",
|
||||||
Username: "telegram",
|
Username: "owpengram",
|
||||||
Verified: true,
|
Verified: true,
|
||||||
Support: true,
|
Support: true,
|
||||||
}
|
}
|
||||||
|
if officialSystemUserPhotoDCID != 0 {
|
||||||
|
u.PhotoID = OfficialSystemUserPhotoID
|
||||||
|
u.PhotoDCID = officialSystemUserPhotoDCID
|
||||||
|
u.PhotoStripped = officialSystemUserPhotoStripped
|
||||||
|
}
|
||||||
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
// BotFatherUser 返回内置 BotFather 账号。username 不以 bot 结尾属种子例外(与官方一致)。
|
// BotFatherUser 返回内置 BotFather 账号。username 不以 bot 结尾属种子例外(与官方一致)。
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue