update
This commit is contained in:
@ -74,7 +74,9 @@ func (h *StreetSnapHandler) Detail(c *gin.Context) {
|
||||
response.Error(c, http.StatusBadRequest, "缺少街拍 id")
|
||||
return
|
||||
}
|
||||
_, numeric, err := hashid.DecodeTyped(raw)
|
||||
// 类型由路由提供(/street-snaps 即 snap)。类型已揉进密码:非 snap 编码的串
|
||||
// 在此解出的是错误主键,查库自然 404,从而强制前端按类型化路由分流(无需靠前缀嗅探)。
|
||||
numeric, err := hashid.DecodeWithType(raw, hashid.TypeSnap)
|
||||
if err != nil {
|
||||
response.Error(c, http.StatusNotFound, "街拍不存在")
|
||||
return
|
||||
@ -82,8 +84,17 @@ func (h *StreetSnapHandler) Detail(c *gin.Context) {
|
||||
|
||||
detail, err := h.svc.Detail(c.Request.Context(), strconv.FormatUint(uint64(numeric), 10))
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
// 向后兼容:迁移前收藏/历史/旧外链可能仍带 s= 前缀(旧 EncodeTyped)。
|
||||
// 主线按类型化密码解码不到实体时,按旧编码再解一次回退(仅当旧类型确为 snap)。
|
||||
if ltyp, lnum, lerr := hashid.DecodeTyped(raw); lerr == nil && ltyp == hashid.TypeSnap {
|
||||
if d2, e2 := h.svc.Detail(c.Request.Context(), strconv.FormatUint(uint64(lnum), 10)); e2 == nil {
|
||||
detail, err = d2, nil
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 未登录:图片集仅返回预览上限(PreviewLimit)张,并打 preview=true,
|
||||
@ -96,7 +107,7 @@ func (h *StreetSnapHandler) Detail(c *gin.Context) {
|
||||
preview = true
|
||||
}
|
||||
|
||||
// 已登录:图集(gallery 级 s=)与每张图片(image 级 j=)收藏态随详情返回,
|
||||
// 已登录:图集(gallery 级 TypeSnap)与每张图片(image 级 TypeSnapImage)收藏态随详情返回,
|
||||
// 前端无需再单独调 /me/favorites/checks。
|
||||
if uid, ok := middleware.UserIDFrom(c); ok {
|
||||
ids := make([]string, 0, len(detail.Images)+1)
|
||||
|
||||
Reference in New Issue
Block a user