feat: 根据 X-App-Id 判断是否裁剪套餐列表,老版客户端去掉最后一个
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 7m37s

This commit is contained in:
shanshanzhong 2026-03-28 23:21:00 -07:00
parent 26c9ff2f0f
commit 3b4e882965
3 changed files with 9 additions and 8 deletions

View File

@ -7,8 +7,7 @@ import (
"github.com/perfect-panel/server/internal/model/subscribe" "github.com/perfect-panel/server/internal/model/subscribe"
"github.com/perfect-panel/server/internal/svc" "github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types" "github.com/perfect-panel/server/internal/types"
// "github.com/perfect-panel/server/pkg/apiversion" "github.com/perfect-panel/server/pkg/constant"
// "github.com/perfect-panel/server/pkg/constant"
"github.com/perfect-panel/server/pkg/logger" "github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool" "github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr" "github.com/perfect-panel/server/pkg/xerr"
@ -60,12 +59,11 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi
list[i] = sub list[i] = sub
} }
// 老版本(无 api-header去掉排序最后一个套餐 // 老版本客户端(无 X-App-Id去掉排序最后一个套餐
// rawVersion, _ := l.ctx.Value(constant.CtxKeyAPIHeaderRaw).(string) hasAppId, _ := l.ctx.Value(constant.CtxKeyHasAppId).(bool)
// useLatest := apiversion.UseLatest(rawVersion, apiversion.DefaultThreshold) if !hasAppId && len(list) > 0 {
// if !useLatest && len(list) > 0 { list = list[:len(list)-1]
// list = list[:len(list)-1] }
// }
resp.List = list resp.List = list
resp.Total = int64(len(list)) resp.Total = int64(len(list))

View File

@ -14,9 +14,11 @@ func ApiVersionMiddleware(_ *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) { return func(c *gin.Context) {
rawVersion := strings.TrimSpace(c.GetHeader("api-header")) rawVersion := strings.TrimSpace(c.GetHeader("api-header"))
useLatest := apiversion.UseLatest(rawVersion, apiversion.DefaultThreshold) useLatest := apiversion.UseLatest(rawVersion, apiversion.DefaultThreshold)
hasAppId := strings.TrimSpace(c.GetHeader("X-App-Id")) != ""
ctx := context.WithValue(c.Request.Context(), constant.CtxKeyAPIVersionUseLatest, useLatest) ctx := context.WithValue(c.Request.Context(), constant.CtxKeyAPIVersionUseLatest, useLatest)
ctx = context.WithValue(ctx, constant.CtxKeyAPIHeaderRaw, rawVersion) ctx = context.WithValue(ctx, constant.CtxKeyAPIHeaderRaw, rawVersion)
ctx = context.WithValue(ctx, constant.CtxKeyHasAppId, hasAppId)
c.Request = c.Request.WithContext(ctx) c.Request = c.Request.WithContext(ctx)
c.Set("api_header", rawVersion) c.Set("api_header", rawVersion)

View File

@ -15,4 +15,5 @@ const (
CtxKeyIncludeExpired CtxKey = "includeExpired" CtxKeyIncludeExpired CtxKey = "includeExpired"
CtxKeyAPIVersionUseLatest CtxKey = "apiVersionUseLatest" CtxKeyAPIVersionUseLatest CtxKey = "apiVersionUseLatest"
CtxKeyAPIHeaderRaw CtxKey = "apiHeaderRaw" CtxKeyAPIHeaderRaw CtxKey = "apiHeaderRaw"
CtxKeyHasAppId CtxKey = "hasAppId"
) )