diff --git a/internal/logic/public/subscribe/querySubscribeListLogic.go b/internal/logic/public/subscribe/querySubscribeListLogic.go index a47276c..4cdbed6 100644 --- a/internal/logic/public/subscribe/querySubscribeListLogic.go +++ b/internal/logic/public/subscribe/querySubscribeListLogic.go @@ -7,8 +7,7 @@ import ( "github.com/perfect-panel/server/internal/model/subscribe" "github.com/perfect-panel/server/internal/svc" "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/tool" "github.com/perfect-panel/server/pkg/xerr" @@ -60,12 +59,11 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi list[i] = sub } - // 老版本(无 api-header)去掉排序最后一个套餐 - // rawVersion, _ := l.ctx.Value(constant.CtxKeyAPIHeaderRaw).(string) - // useLatest := apiversion.UseLatest(rawVersion, apiversion.DefaultThreshold) - // if !useLatest && len(list) > 0 { - // list = list[:len(list)-1] - // } + // 老版本客户端(无 X-App-Id)去掉排序最后一个套餐 + hasAppId, _ := l.ctx.Value(constant.CtxKeyHasAppId).(bool) + if !hasAppId && len(list) > 0 { + list = list[:len(list)-1] + } resp.List = list resp.Total = int64(len(list)) diff --git a/internal/middleware/apiVersionMiddleware.go b/internal/middleware/apiVersionMiddleware.go index 845a54d..7362772 100644 --- a/internal/middleware/apiVersionMiddleware.go +++ b/internal/middleware/apiVersionMiddleware.go @@ -14,9 +14,11 @@ func ApiVersionMiddleware(_ *svc.ServiceContext) func(c *gin.Context) { return func(c *gin.Context) { rawVersion := strings.TrimSpace(c.GetHeader("api-header")) 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(ctx, constant.CtxKeyAPIHeaderRaw, rawVersion) + ctx = context.WithValue(ctx, constant.CtxKeyHasAppId, hasAppId) c.Request = c.Request.WithContext(ctx) c.Set("api_header", rawVersion) diff --git a/pkg/constant/context.go b/pkg/constant/context.go index ea20e2a..9a8f2d7 100644 --- a/pkg/constant/context.go +++ b/pkg/constant/context.go @@ -15,4 +15,5 @@ const ( CtxKeyIncludeExpired CtxKey = "includeExpired" CtxKeyAPIVersionUseLatest CtxKey = "apiVersionUseLatest" CtxKeyAPIHeaderRaw CtxKey = "apiHeaderRaw" + CtxKeyHasAppId CtxKey = "hasAppId" )