This commit is contained in:
toom1996
2026-09-16 00:56:15 +08:00
parent 5e4803b97f
commit 7dd3fda73c
10 changed files with 184 additions and 54 deletions

View File

@ -67,7 +67,7 @@ func (s *streetSnapService) List(ctx context.Context, q dto.StreetSnapQuery) ([]
for _, r := range rows {
ids = append(ids, r.ID)
list = append(list, dto.PublicStreetSnap{
UID: hashid.EncodeTyped(hashid.TypeSnap, r.ID),
UID: hashid.EncodeWithType(r.ID, hashid.TypeSnap),
Title: r.Title,
Cover: s.img.ComposeThumb(r.Cover), // 列表封面走缩略图样式(小尺寸省流量)
ImageCount: r.ImageCount,
@ -135,7 +135,7 @@ func (s *streetSnapService) Detail(ctx context.Context, id string) (*dto.PublicS
}
return &dto.PublicStreetSnapDetail{
UID: hashid.EncodeTyped(hashid.TypeSnap, snap.ID),
UID: hashid.EncodeWithType(snap.ID, hashid.TypeSnap),
Title: snap.Title,
Cover: s.img.Compose(snap.Cover),
Images: s.toPublicSnapImages(imgs),
@ -152,7 +152,7 @@ func (s *streetSnapService) Popular(ctx context.Context, limit int) ([]dto.Publi
list := make([]dto.PublicStreetSnap, 0, len(rows))
for _, r := range rows {
list = append(list, dto.PublicStreetSnap{
UID: hashid.EncodeTyped(hashid.TypeSnap, r.ID),
UID: hashid.EncodeWithType(r.ID, hashid.TypeSnap),
Title: r.Title,
Cover: s.img.Compose(r.Cover), // 首页热门街拍卡片为大图展示,用高清样式(high)
ImageCount: r.ImageCount,
@ -162,7 +162,7 @@ func (s *streetSnapService) Popular(ctx context.Context, limit int) ([]dto.Publi
}
// toPublicSnapImages 把图片实体映射为对外结构(url + 名称 + 图片自身的编码 id)。
// ID 用 TypeSnapImage 前缀编码,与街拍 uid(s 前缀)区分开,供单图收藏定位。
// ID 用 EncodeWithType(TypeSnapImage) 编码(类型进密码、无前缀),与街拍图集 uid 区分开,供单图收藏定位。
// Image 走展示样式(high);额外给出 Thumb(缩略图样式),供大图灯箱左栏缩略图条等
// 小尺寸场景使用(列表用的 toThumbSnapImages 不填 Thumb,其 Image 本身就是缩略图)。
func (s *streetSnapService) toPublicSnapImages(imgs []model.StreetSnapImage) []dto.PublicArticleImage {
@ -172,7 +172,7 @@ func (s *streetSnapService) toPublicSnapImages(imgs []model.StreetSnapImage) []d
out := make([]dto.PublicArticleImage, 0, len(imgs))
for _, im := range imgs {
out = append(out, dto.PublicArticleImage{
ID: hashid.EncodeTyped(hashid.TypeSnapImage, im.ID),
ID: hashid.EncodeWithType(im.ID, hashid.TypeSnapImage),
Image: s.img.Compose(im.Image),
Thumb: s.img.ComposeThumb(im.Image),
Name: im.Name,
@ -190,7 +190,7 @@ func (s *streetSnapService) toThumbSnapImages(imgs []model.StreetSnapImage) []dt
out := make([]dto.PublicArticleImage, 0, len(imgs))
for _, im := range imgs {
out = append(out, dto.PublicArticleImage{
ID: hashid.EncodeTyped(hashid.TypeSnapImage, im.ID),
ID: hashid.EncodeWithType(im.ID, hashid.TypeSnapImage),
Image: s.img.ComposeThumb(im.Image),
Name: im.Name,
})