mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
feat:change fcm path
This commit is contained in:
parent
e32d30f287
commit
1e3eaade5a
11
internal/push/offlinepush/fcm/filepath_test.go
Normal file
11
internal/push/offlinepush/fcm/filepath_test.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package fcm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFilePath(t *testing.T) {
|
||||||
|
fmt.Println(filepath.Join("a/b/", "a.json"))
|
||||||
|
}
|
||||||
@ -40,12 +40,13 @@ type Fcm struct {
|
|||||||
|
|
||||||
// NewClient initializes a new FCM client using the Firebase Admin SDK.
|
// 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.
|
// 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) {
|
func NewClient(pushConf *config.Push, cache cache.ThirdCache, fcmPath string) (*Fcm, error) {
|
||||||
projectRoot, err := config.GetProjectRoot()
|
//projectRoot, err := config.GetProjectRoot()
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
//}
|
||||||
credentialsFilePath := filepath.Join(projectRoot, "config", pushConf.FCM.ServiceAccount)
|
projectRoot := fcmPath
|
||||||
|
credentialsFilePath := filepath.Join(projectRoot, pushConf.FCM.ServiceAccount)
|
||||||
opt := option.WithCredentialsFile(credentialsFilePath)
|
opt := option.WithCredentialsFile(credentialsFilePath)
|
||||||
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
|
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -36,13 +36,13 @@ type OfflinePusher interface {
|
|||||||
Push(ctx context.Context, userIDs []string, title, content string, opts *options.Opts) error
|
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
|
var offlinePusher OfflinePusher
|
||||||
switch pushConf.Enable {
|
switch pushConf.Enable {
|
||||||
case geTUI:
|
case geTUI:
|
||||||
offlinePusher = getui.NewClient(pushConf, cache)
|
offlinePusher = getui.NewClient(pushConf, cache)
|
||||||
case firebase:
|
case firebase:
|
||||||
return fcm.NewClient(pushConf, cache)
|
return fcm.NewClient(pushConf, cache, fcmPath)
|
||||||
case jPush:
|
case jPush:
|
||||||
offlinePusher = jpush.NewClient(pushConf)
|
offlinePusher = jpush.NewClient(pushConf)
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -29,6 +29,7 @@ type Config struct {
|
|||||||
WebhooksConfig config.Webhooks
|
WebhooksConfig config.Webhooks
|
||||||
LocalCacheConfig config.LocalCache
|
LocalCacheConfig config.LocalCache
|
||||||
Discovery config.Discovery
|
Discovery config.Discovery
|
||||||
|
FcmPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p pushServer) PushMsg(ctx context.Context, req *pbpush.PushMsgReq) (*pbpush.PushMsgResp, error) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
cacheModel := redis.NewThirdCache(rdb)
|
cacheModel := redis.NewThirdCache(rdb)
|
||||||
offlinePusher, err := offlinepush.NewOfflinePusher(&config.RpcConfig, cacheModel)
|
offlinePusher, err := offlinepush.NewOfflinePusher(&config.RpcConfig, cacheModel, config.FcmPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,6 +44,7 @@ func NewPushRpcCmd() *PushRpcCmd {
|
|||||||
LocalCacheConfigFileName: &pushConfig.LocalCacheConfig,
|
LocalCacheConfigFileName: &pushConfig.LocalCacheConfig,
|
||||||
DiscoveryConfigFilename: &pushConfig.Discovery,
|
DiscoveryConfigFilename: &pushConfig.Discovery,
|
||||||
}
|
}
|
||||||
|
ret.pushConfig.FcmPath = ret.FcmPath()
|
||||||
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
|
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
|
||||||
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
|
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
|
||||||
ret.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
ret.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
|||||||
@ -31,6 +31,11 @@ type RootCmd struct {
|
|||||||
prometheusPort int
|
prometheusPort int
|
||||||
log config.Log
|
log config.Log
|
||||||
index int
|
index int
|
||||||
|
fcmPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RootCmd) FcmPath() string {
|
||||||
|
return r.fcmPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RootCmd) Index() int {
|
func (r *RootCmd) Index() int {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user