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

@ -70,7 +70,7 @@ func (s *articleService) List(ctx context.Context, q dto.ArticleQuery) ([]dto.Pu
for _, r := range rows {
ids = append(ids, r.ID)
list = append(list, dto.PublicArticle{
UID: hashid.EncodeTyped(hashid.TypeRunway, r.ID),
UID: hashid.EncodeWithType(r.ID, hashid.TypeRunway),
BrandUID: hashid.Encode(r.BrandID),
Title: pickLocale(r.TitleEn, r.TitleCn, q.Locale),
Cover: s.img.ComposeThumb(r.Cover), // 列表封面走缩略图样式(小尺寸省流量)
@ -98,7 +98,7 @@ func (s *articleService) AdminList(ctx context.Context, q dto.ArticleQuery) ([]d
list := make([]dto.AdminRunway, 0, len(rows))
for _, r := range rows {
list = append(list, dto.AdminRunway{
UID: hashid.EncodeTyped(hashid.TypeRunway, r.ID),
UID: hashid.EncodeWithType(r.ID, hashid.TypeRunway),
BrandUID: hashid.Encode(r.BrandID),
BrandName: pickLocale(r.BrandNameEn, r.BrandNameCn, "en"),
Title: pickLocale(r.TitleEn, r.TitleCn, q.Locale),
@ -190,7 +190,7 @@ func (s *articleService) Detail(ctx context.Context, id string, locale string) (
}
return &dto.PublicArticleDetail{
UID: hashid.EncodeTyped(hashid.TypeRunway, row.ID),
UID: hashid.EncodeWithType(row.ID, hashid.TypeRunway),
BrandUID: hashid.Encode(row.BrandID),
Title: pickLocale(row.TitleEn, row.TitleCn, locale),
Description: pickLocale(row.DescriptionEn, row.DescriptionCn, locale),
@ -274,7 +274,7 @@ func (s *articleService) toPublicImages(imgs []model.BrandRunwayImage) []dto.Pub
out := make([]dto.PublicArticleImage, 0, len(imgs))
for _, im := range imgs {
out = append(out, dto.PublicArticleImage{
ID: hashid.EncodeTyped(hashid.TypeRunwayImage, im.ID),
ID: hashid.EncodeWithType(im.ID, hashid.TypeRunwayImage),
Image: s.img.Compose(im.Image),
Thumb: s.img.ComposeThumb(im.Image),
Name: im.Name,
@ -294,7 +294,7 @@ func (s *articleService) toThumbImages(imgs []model.BrandRunwayImage) []dto.Publ
out := make([]dto.PublicArticleImage, 0, len(imgs))
for _, im := range imgs {
out = append(out, dto.PublicArticleImage{
ID: hashid.EncodeTyped(hashid.TypeRunwayImage, im.ID),
ID: hashid.EncodeWithType(im.ID, hashid.TypeRunwayImage),
Image: s.img.ComposeThumb(im.Image),
Name: im.Name,
IsDetail: im.IsDetail,

View File

@ -51,8 +51,8 @@ func (s *indexService) Runway(ctx context.Context, locale string) (IndexRunwayDa
brands := make([]dto.PopularBrand, 0, len(rows))
for _, b := range rows {
brands = append(brands, dto.PopularBrand{
UID: hashid.Encode(b.ID),
ArticleUID: hashid.Encode(b.ArticleID),
UID: hashid.Encode(b.ID), // 品牌无类型,继续用全局编码(brand handler 用 Decode 解码)
ArticleUID: hashid.EncodeWithType(b.ArticleID, hashid.TypeRunway), // 走秀详情链接用类型化编码
// 品牌名强制优先英文("en"),不随 locale 切换,保持英文观感。
Brand: pickLocale(b.BrandEn, b.BrandCn, "en"),
Cover: s.img.Compose(b.Cover), // 首页热门卡片为大图展示,用高清样式(high)

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,
})