Skip to content

Commit

Permalink
Merge branch 'fix-group-and-config' of https://github.com/icey-yu/ope…
Browse files Browse the repository at this point in the history
…n-im-server into fix-group-and-config
  • Loading branch information
icey-yu committed Jun 11, 2024
2 parents b340962 + 19cabd9 commit 78e02fd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
11 changes: 11 additions & 0 deletions internal/push/offlinepush/fcm/filepath_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fcm

import (
"fmt"
"path/filepath"
"testing"
)

func TestFilePath(t *testing.T) {
fmt.Println(filepath.Join("a/b/", "a.json"))
}
12 changes: 6 additions & 6 deletions internal/push/offlinepush/fcm/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +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) (*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, fcmConfigPath string) (*Fcm, error) {
//projectRoot, err := config.GetProjectRoot()
//if err != nil {
// return nil, err
//}
credentialsFilePath := filepath.Join(fcmConfigPath, pushConf.FCM.ServiceAccount)
opt := option.WithCredentialsFile(credentialsFilePath)
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/push/offlinepush/offlinepusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, fcmConfigPath 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, fcmConfigPath)
case jPush:
offlinePusher = jpush.NewClient(pushConf)
default:
Expand Down
3 changes: 2 additions & 1 deletion internal/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Config struct {
WebhooksConfig config.Webhooks
LocalCacheConfig config.LocalCache
Discovery config.Discovery
FcmConfigPath string
}

func (p pushServer) PushMsg(ctx context.Context, req *pbpush.PushMsgReq) (*pbpush.PushMsgResp, error) {
Expand All @@ -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.FcmConfigPath)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/common/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func NewPushRpcCmd() *PushRpcCmd {
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()
return ret.runE()
}
return ret
Expand Down
6 changes: 6 additions & 0 deletions pkg/common/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type RootCmd struct {
prometheusPort int
log config.Log
index int
configPath string
}

func (r *RootCmd) ConfigPath() string {
return r.configPath
}

func (r *RootCmd) Index() int {
Expand Down Expand Up @@ -153,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)
Expand Down

0 comments on commit 78e02fd

Please sign in to comment.