From 1e3eaade5a7c7510624fd1ba65ae869675e623f2 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Fri, 7 Jun 2024 19:04:04 +0800 Subject: [PATCH 1/5] feat:change fcm path --- internal/push/offlinepush/fcm/filepath_test.go | 11 +++++++++++ internal/push/offlinepush/fcm/push.go | 13 +++++++------ internal/push/offlinepush/offlinepusher.go | 4 ++-- internal/push/push.go | 3 ++- pkg/common/cmd/push.go | 1 + pkg/common/cmd/root.go | 5 +++++ 6 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 internal/push/offlinepush/fcm/filepath_test.go diff --git a/internal/push/offlinepush/fcm/filepath_test.go b/internal/push/offlinepush/fcm/filepath_test.go new file mode 100644 index 0000000000..ccb760a659 --- /dev/null +++ b/internal/push/offlinepush/fcm/filepath_test.go @@ -0,0 +1,11 @@ +package fcm + +import ( + "fmt" + "path/filepath" + "testing" +) + +func TestFilePath(t *testing.T) { + fmt.Println(filepath.Join("a/b/", "a.json")) +} diff --git a/internal/push/offlinepush/fcm/push.go b/internal/push/offlinepush/fcm/push.go index ec973008e3..38a9c94d53 100644 --- a/internal/push/offlinepush/fcm/push.go +++ b/internal/push/offlinepush/fcm/push.go @@ -40,12 +40,13 @@ type Fcm struct { // NewClient initializes a new FCM client using the Firebase Admin SDK. // It requires the FCM service account credentials file located within the project's configuration directory. -func NewClient(pushConf *config.Push, cache cache.ThirdCache) (*Fcm, error) { - projectRoot, err := config.GetProjectRoot() - if err != nil { - return nil, err - } - credentialsFilePath := filepath.Join(projectRoot, "config", pushConf.FCM.ServiceAccount) +func NewClient(pushConf *config.Push, cache cache.ThirdCache, fcmPath string) (*Fcm, error) { + //projectRoot, err := config.GetProjectRoot() + //if err != nil { + // return nil, err + //} + projectRoot := fcmPath + credentialsFilePath := filepath.Join(projectRoot, pushConf.FCM.ServiceAccount) opt := option.WithCredentialsFile(credentialsFilePath) fcmApp, err := firebase.NewApp(context.Background(), nil, opt) if err != nil { diff --git a/internal/push/offlinepush/offlinepusher.go b/internal/push/offlinepush/offlinepusher.go index 8dc8a0bc6b..a1e9b88095 100644 --- a/internal/push/offlinepush/offlinepusher.go +++ b/internal/push/offlinepush/offlinepusher.go @@ -36,13 +36,13 @@ type OfflinePusher interface { Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error } -func NewOfflinePusher(pushConf *config.Push, cache cache.ThirdCache) (OfflinePusher, error) { +func NewOfflinePusher(pushConf *config.Push, cache cache.ThirdCache, fcmPath string) (OfflinePusher, error) { var offlinePusher OfflinePusher switch pushConf.Enable { case geTUI: offlinePusher = getui.NewClient(pushConf, cache) case firebase: - return fcm.NewClient(pushConf, cache) + return fcm.NewClient(pushConf, cache, fcmPath) case jPush: offlinePusher = jpush.NewClient(pushConf) default: diff --git a/internal/push/push.go b/internal/push/push.go index c7e245dfe2..2ecc6da202 100644 --- a/internal/push/push.go +++ b/internal/push/push.go @@ -29,6 +29,7 @@ type Config struct { WebhooksConfig config.Webhooks LocalCacheConfig config.LocalCache Discovery config.Discovery + FcmPath string } func (p pushServer) PushMsg(ctx context.Context, req *pbpush.PushMsgReq) (*pbpush.PushMsgResp, error) { @@ -50,7 +51,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg return err } cacheModel := redis.NewThirdCache(rdb) - offlinePusher, err := offlinepush.NewOfflinePusher(&config.RpcConfig, cacheModel) + offlinePusher, err := offlinepush.NewOfflinePusher(&config.RpcConfig, cacheModel, config.FcmPath) if err != nil { return err } diff --git a/pkg/common/cmd/push.go b/pkg/common/cmd/push.go index 3e7c4c2492..44c3e58268 100644 --- a/pkg/common/cmd/push.go +++ b/pkg/common/cmd/push.go @@ -44,6 +44,7 @@ func NewPushRpcCmd() *PushRpcCmd { LocalCacheConfigFileName: &pushConfig.LocalCacheConfig, DiscoveryConfigFilename: &pushConfig.Discovery, } + ret.pushConfig.FcmPath = ret.FcmPath() ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap)) ret.ctx = context.WithValue(context.Background(), "version", config.Version) ret.Command.RunE = func(cmd *cobra.Command, args []string) error { diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 9002813676..65031c5ff8 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -31,6 +31,11 @@ type RootCmd struct { prometheusPort int log config.Log index int + fcmPath string +} + +func (r *RootCmd) FcmPath() string { + return r.fcmPath } func (r *RootCmd) Index() int { From 7065b5f81b7c8308aba8b26b1e34de9457157842 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Fri, 7 Jun 2024 19:14:08 +0800 Subject: [PATCH 2/5] fix: change fcm config path --- internal/push/offlinepush/fcm/push.go | 5 ++--- internal/push/offlinepush/offlinepusher.go | 4 ++-- internal/push/push.go | 4 ++-- pkg/common/cmd/push.go | 2 +- pkg/common/cmd/root.go | 7 ++++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/push/offlinepush/fcm/push.go b/internal/push/offlinepush/fcm/push.go index 38a9c94d53..06eef01879 100644 --- a/internal/push/offlinepush/fcm/push.go +++ b/internal/push/offlinepush/fcm/push.go @@ -40,13 +40,12 @@ type Fcm struct { // NewClient initializes a new FCM client using the Firebase Admin SDK. // It requires the FCM service account credentials file located within the project's configuration directory. -func NewClient(pushConf *config.Push, cache cache.ThirdCache, fcmPath string) (*Fcm, error) { +func NewClient(pushConf *config.Push, cache cache.ThirdCache, fcmConfigPath string) (*Fcm, error) { //projectRoot, err := config.GetProjectRoot() //if err != nil { // return nil, err //} - projectRoot := fcmPath - credentialsFilePath := filepath.Join(projectRoot, pushConf.FCM.ServiceAccount) + credentialsFilePath := filepath.Join(fcmConfigPath, pushConf.FCM.ServiceAccount) opt := option.WithCredentialsFile(credentialsFilePath) fcmApp, err := firebase.NewApp(context.Background(), nil, opt) if err != nil { diff --git a/internal/push/offlinepush/offlinepusher.go b/internal/push/offlinepush/offlinepusher.go index a1e9b88095..9aa6625deb 100644 --- a/internal/push/offlinepush/offlinepusher.go +++ b/internal/push/offlinepush/offlinepusher.go @@ -36,13 +36,13 @@ type OfflinePusher interface { Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error } -func NewOfflinePusher(pushConf *config.Push, cache cache.ThirdCache, fcmPath string) (OfflinePusher, error) { +func NewOfflinePusher(pushConf *config.Push, cache cache.ThirdCache, fcmConfigPath string) (OfflinePusher, error) { var offlinePusher OfflinePusher switch pushConf.Enable { case geTUI: offlinePusher = getui.NewClient(pushConf, cache) case firebase: - return fcm.NewClient(pushConf, cache, fcmPath) + return fcm.NewClient(pushConf, cache, fcmConfigPath) case jPush: offlinePusher = jpush.NewClient(pushConf) default: diff --git a/internal/push/push.go b/internal/push/push.go index 2ecc6da202..1a04bbea26 100644 --- a/internal/push/push.go +++ b/internal/push/push.go @@ -29,7 +29,7 @@ type Config struct { WebhooksConfig config.Webhooks LocalCacheConfig config.LocalCache Discovery config.Discovery - FcmPath string + FcmConfigPath string } func (p pushServer) PushMsg(ctx context.Context, req *pbpush.PushMsgReq) (*pbpush.PushMsgResp, error) { @@ -51,7 +51,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg return err } cacheModel := redis.NewThirdCache(rdb) - offlinePusher, err := offlinepush.NewOfflinePusher(&config.RpcConfig, cacheModel, config.FcmPath) + offlinePusher, err := offlinepush.NewOfflinePusher(&config.RpcConfig, cacheModel, config.FcmConfigPath) if err != nil { return err } diff --git a/pkg/common/cmd/push.go b/pkg/common/cmd/push.go index 44c3e58268..0594b41004 100644 --- a/pkg/common/cmd/push.go +++ b/pkg/common/cmd/push.go @@ -44,7 +44,7 @@ func NewPushRpcCmd() *PushRpcCmd { LocalCacheConfigFileName: &pushConfig.LocalCacheConfig, DiscoveryConfigFilename: &pushConfig.Discovery, } - ret.pushConfig.FcmPath = ret.FcmPath() + ret.pushConfig.FcmPath = ret.ConfigPath() ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap)) ret.ctx = context.WithValue(context.Background(), "version", config.Version) ret.Command.RunE = func(cmd *cobra.Command, args []string) error { diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 65031c5ff8..08bb6d0642 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -31,11 +31,11 @@ type RootCmd struct { prometheusPort int log config.Log index int - fcmPath string + configPath string } -func (r *RootCmd) FcmPath() string { - return r.fcmPath +func (r *RootCmd) ConfigPath() string { + return r.configPath } func (r *RootCmd) Index() int { @@ -158,6 +158,7 @@ func (r *RootCmd) getFlag(cmd *cobra.Command) (string, int, error) { if err != nil { return "", 0, errs.Wrap(err) } + r.configPath = configDirectory index, err := cmd.Flags().GetInt(FlagTransferIndex) if err != nil { return "", 0, errs.Wrap(err) From 0ef42b1896dfaa2ecab28d93bcfec41301ffebbb Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Fri, 7 Jun 2024 19:18:30 +0800 Subject: [PATCH 3/5] fix: config read --- pkg/common/cmd/push.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/common/cmd/push.go b/pkg/common/cmd/push.go index 0594b41004..4b8cf7b6f4 100644 --- a/pkg/common/cmd/push.go +++ b/pkg/common/cmd/push.go @@ -44,10 +44,10 @@ func NewPushRpcCmd() *PushRpcCmd { LocalCacheConfigFileName: &pushConfig.LocalCacheConfig, DiscoveryConfigFilename: &pushConfig.Discovery, } - ret.pushConfig.FcmPath = ret.ConfigPath() - ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap)) + ret.pushConfig.FcmConfigPath = ret.ConfigPath() ret.ctx = context.WithValue(context.Background(), "version", config.Version) ret.Command.RunE = func(cmd *cobra.Command, args []string) error { + ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap)) return ret.runE() } return ret From 4fa86bd3b505ecab4dd2813896c84077d435e182 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Fri, 7 Jun 2024 19:20:30 +0800 Subject: [PATCH 4/5] fix: config read --- pkg/common/cmd/push.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/common/cmd/push.go b/pkg/common/cmd/push.go index 4b8cf7b6f4..89bfbf4d29 100644 --- a/pkg/common/cmd/push.go +++ b/pkg/common/cmd/push.go @@ -19,7 +19,6 @@ import ( "github.com/openimsdk/open-im-server/v3/internal/push" "github.com/openimsdk/open-im-server/v3/pkg/common/config" "github.com/openimsdk/open-im-server/v3/pkg/common/startrpc" - "github.com/openimsdk/tools/system/program" "github.com/spf13/cobra" ) @@ -44,10 +43,9 @@ func NewPushRpcCmd() *PushRpcCmd { LocalCacheConfigFileName: &pushConfig.LocalCacheConfig, DiscoveryConfigFilename: &pushConfig.Discovery, } - ret.pushConfig.FcmConfigPath = ret.ConfigPath() ret.ctx = context.WithValue(context.Background(), "version", config.Version) ret.Command.RunE = func(cmd *cobra.Command, args []string) error { - ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap)) + ret.pushConfig.FcmConfigPath = ret.ConfigPath() return ret.runE() } return ret From 19cabd9e6b2ea98f975dac318b8d74ab7c0e7cdb Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Fri, 7 Jun 2024 19:22:06 +0800 Subject: [PATCH 5/5] fix: config read --- pkg/common/cmd/push.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/common/cmd/push.go b/pkg/common/cmd/push.go index 89bfbf4d29..6e6014021e 100644 --- a/pkg/common/cmd/push.go +++ b/pkg/common/cmd/push.go @@ -19,6 +19,7 @@ import ( "github.com/openimsdk/open-im-server/v3/internal/push" "github.com/openimsdk/open-im-server/v3/pkg/common/config" "github.com/openimsdk/open-im-server/v3/pkg/common/startrpc" + "github.com/openimsdk/tools/system/program" "github.com/spf13/cobra" ) @@ -43,6 +44,7 @@ func NewPushRpcCmd() *PushRpcCmd { LocalCacheConfigFileName: &pushConfig.LocalCacheConfig, DiscoveryConfigFilename: &pushConfig.Discovery, } + ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap)) ret.ctx = context.WithValue(context.Background(), "version", config.Version) ret.Command.RunE = func(cmd *cobra.Command, args []string) error { ret.pushConfig.FcmConfigPath = ret.ConfigPath()