update
This commit is contained in:
@ -89,7 +89,9 @@ func (h *ArticleHandler) Detail(c *gin.Context) {
|
||||
response.Error(c, http.StatusBadRequest, "缺少文章 id")
|
||||
return
|
||||
}
|
||||
_, numeric, err := hashid.DecodeTyped(raw)
|
||||
// 类型由路由提供(/runway-looks 即 runway)。类型已揉进密码:非 runway 编码的串
|
||||
// 在此解出的是错误主键,查库自然 404,从而强制前端按类型化路由分流(无需靠前缀嗅探)。
|
||||
numeric, err := hashid.DecodeWithType(raw, hashid.TypeRunway)
|
||||
if err != nil {
|
||||
response.Error(c, http.StatusNotFound, "文章不存在")
|
||||
return
|
||||
@ -97,8 +99,17 @@ func (h *ArticleHandler) Detail(c *gin.Context) {
|
||||
|
||||
detail, err := h.articles.Detail(c.Request.Context(), strconv.FormatUint(uint64(numeric), 10), parseLocale(c))
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
// 向后兼容:迁移前收藏/历史/旧外链可能仍带 r= 前缀(旧 EncodeTyped)。
|
||||
// 主线按类型化密码解码不到实体时,按旧编码再解一次回退(仅当旧类型确为 runway)。
|
||||
if ltyp, lnum, lerr := hashid.DecodeTyped(raw); lerr == nil && ltyp == hashid.TypeRunway {
|
||||
if d2, e2 := h.articles.Detail(c.Request.Context(), strconv.FormatUint(uint64(lnum), 10), parseLocale(c)); e2 == nil {
|
||||
detail, err = d2, nil
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
fail(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 未登录:主图只返回预览上限(PreviewLimit)张并打 preview=true,前端据此展示
|
||||
@ -112,9 +123,9 @@ func (h *ArticleHandler) Detail(c *gin.Context) {
|
||||
preview = true
|
||||
}
|
||||
|
||||
// 已登录:把当前用户对该图集(gallery 级)与每张图片(image 级,含细节图)的收藏态
|
||||
// 随详情返回,前端无需再单独调 /me/favorites/checks。gallery uid(r=)与图片 id(i=)
|
||||
// 前缀不同,混传 FilterExisting 不影响查询;匿名请求不查(保持公开接口无用户态、可缓存)。
|
||||
// 已登录:把当前用户对该图集(gallery 级 TypeRunway)与每张图片(image 级 TypeRunwayImage,含细节图)的收藏态
|
||||
// 随详情返回,前端无需再单独调 /me/favorites/checks。gallery uid 与图片 id 因类型进密码、串值不同,
|
||||
// 混传 FilterExisting 不影响查询;匿名请求不查(保持公开接口无用户态、可缓存)。
|
||||
if uid, ok := middleware.UserIDFrom(c); ok {
|
||||
ids := make([]string, 0, len(detail.Images)*2+1)
|
||||
ids = append(ids, detail.UID)
|
||||
|
||||
Reference in New Issue
Block a user