From 3b4e88296524081d6d00243a89ef90c107df4e34 Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Sat, 28 Mar 2026 23:21:00 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=B9=E6=8D=AE=20X-App-Id=20?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E8=A3=81=E5=89=AA=E5=A5=97?= =?UTF-8?q?=E9=A4=90=E5=88=97=E8=A1=A8=EF=BC=8C=E8=80=81=E7=89=88=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=8E=BB=E6=8E=89=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/subscribe/querySubscribeListLogic.go | 14 ++++++-------- internal/middleware/apiVersionMiddleware.go | 2 ++ pkg/constant/context.go | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) 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" )