From cb5bf5aae34e3ef15c1c3d9799c40f60bcce906c Mon Sep 17 00:00:00 2001 From: Chang lue Tsen Date: Sun, 9 Nov 2025 09:06:42 -0500 Subject: [PATCH] feat(module): add GetModuleConfig handler and logic for module configuration retrieval --- .../admin/system/getModuleConfigHandler.go | 18 ++++++++ internal/handler/routes.go | 6 +-- .../admin/system/getModuleConfigLogic.go | 41 +++++++++++++++++++ internal/types/types.go | 14 +++---- 4 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 internal/handler/admin/system/getModuleConfigHandler.go create mode 100644 internal/logic/admin/system/getModuleConfigLogic.go diff --git a/internal/handler/admin/system/getModuleConfigHandler.go b/internal/handler/admin/system/getModuleConfigHandler.go new file mode 100644 index 0000000..72f87a3 --- /dev/null +++ b/internal/handler/admin/system/getModuleConfigHandler.go @@ -0,0 +1,18 @@ +package system + +import ( + "github.com/gin-gonic/gin" + "github.com/perfect-panel/server/internal/logic/admin/system" + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/pkg/result" +) + +// GetModuleConfigHandler Get Module Config +func GetModuleConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) { + return func(c *gin.Context) { + + l := system.NewGetModuleConfigLogic(c.Request.Context(), svcCtx) + resp, err := l.GetModuleConfig() + result.HttpResult(c, resp, err) + } +} diff --git a/internal/handler/routes.go b/internal/handler/routes.go index 943ba84..03ea6c1 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -408,6 +408,9 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) { // Update invite config adminSystemGroupRouter.PUT("/invite_config", adminSystem.UpdateInviteConfigHandler(serverCtx)) + // Get Module Config + adminSystemGroupRouter.GET("/module", adminSystem.GetModuleConfigHandler(serverCtx)) + // Get node config adminSystemGroupRouter.GET("/node_config", adminSystem.GetNodeConfigHandler(serverCtx)) @@ -822,9 +825,6 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) { // Reset User Subscribe Token publicUserGroupRouter.PUT("/subscribe_token", publicUser.ResetUserSubscribeTokenHandler(serverCtx)) - // Update User Subscribe Note - publicUserGroupRouter.PUT("/subscribe_note", publicUser.UpdateUserSubscribeNoteHandler(serverCtx)) - // Unbind Device publicUserGroupRouter.PUT("/unbind_device", publicUser.UnbindDeviceHandler(serverCtx)) diff --git a/internal/logic/admin/system/getModuleConfigLogic.go b/internal/logic/admin/system/getModuleConfigLogic.go new file mode 100644 index 0000000..2dc646f --- /dev/null +++ b/internal/logic/admin/system/getModuleConfigLogic.go @@ -0,0 +1,41 @@ +package system + +import ( + "context" + "os" + + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/internal/types" + "github.com/perfect-panel/server/pkg/constant" + "github.com/perfect-panel/server/pkg/logger" + "github.com/perfect-panel/server/pkg/xerr" + "github.com/pkg/errors" +) + +type GetModuleConfigLogic struct { + logger.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// Get Module Config +func NewGetModuleConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetModuleConfigLogic { + return &GetModuleConfigLogic{ + Logger: logger.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetModuleConfigLogic) GetModuleConfig() (resp *types.ModuleConfig, err error) { + value, exists := os.LookupEnv("SECRET_KEY") + if !exists { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), " SECRET_KEY not set in environment variables") + } + + return &types.ModuleConfig{ + Secret: value, + ServiceName: constant.ServiceName, + ServiceVersion: constant.Version, + }, nil +} diff --git a/internal/types/types.go b/internal/types/types.go index 9611bac..ddd090f 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1221,6 +1221,12 @@ type MobileAuthenticateConfig struct { Whitelist []string `json:"whitelist"` } +type ModuleConfig struct { + Secret string `json:"secret"` // 通讯密钥 + ServiceName string `json:"service_name"` // 服务名称 + ServiceVersion string `json:"service_version"` // 服务版本 +} + type Node struct { Id int64 `json:"id"` Name string `json:"name"` @@ -1804,11 +1810,6 @@ type ResetUserSubscribeTokenRequest struct { UserSubscribeId int64 `json:"user_subscribe_id"` } -type UpdateUserSubscribeNoteRequest struct { - UserSubscribeId int64 `json:"user_subscribe_id" validate:"required"` - Note string `json:"note" validate:"max=500"` -} - type RevenueStatisticsResponse struct { Today OrdersStatistics `json:"today"` Monthly OrdersStatistics `json:"monthly"` @@ -2581,7 +2582,6 @@ type UserSubscribe struct { Upload int64 `json:"upload"` Token string `json:"token"` Status uint8 `json:"status"` - Note string `json:"note"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } @@ -2601,7 +2601,6 @@ type UserSubscribeDetail struct { Upload int64 `json:"upload"` Token string `json:"token"` Status uint8 `json:"status"` - Note string `json:"note"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } @@ -2620,7 +2619,6 @@ type UserSubscribeInfo struct { Upload int64 `json:"upload"` Token string `json:"token"` Status uint8 `json:"status"` - Note string `json:"note"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` IsTryOut bool `json:"is_try_out"`