Add build tags for Firebase
This commit is contained in:
@@ -279,6 +279,8 @@ func execServe(c *cli.Context) error {
|
|||||||
// Check values
|
// Check values
|
||||||
if firebaseKeyFile != "" && !util.FileExists(firebaseKeyFile) {
|
if firebaseKeyFile != "" && !util.FileExists(firebaseKeyFile) {
|
||||||
return errors.New("if set, FCM key file must exist")
|
return errors.New("if set, FCM key file must exist")
|
||||||
|
} else if firebaseKeyFile != "" && !server.FirebaseAvailable {
|
||||||
|
return errors.New("cannot set firebase-key-file, support for Firebase is not available (nofirebase)")
|
||||||
} else if webPushPublicKey != "" && (webPushPrivateKey == "" || webPushFile == "" || webPushEmailAddress == "" || baseURL == "") {
|
} else if webPushPublicKey != "" && (webPushPrivateKey == "" || webPushFile == "" || webPushEmailAddress == "" || baseURL == "") {
|
||||||
return errors.New("if web push is enabled, web-push-private-key, web-push-public-key, web-push-file, web-push-email-address, and base-url should be set. run 'ntfy webpush keys' to generate keys")
|
return errors.New("if web push is enabled, web-push-private-key, web-push-public-key, web-push-file, web-push-email-address, and base-url should be set. run 'ntfy webpush keys' to generate keys")
|
||||||
} else if keepaliveInterval < 5*time.Second {
|
} else if keepaliveInterval < 5*time.Second {
|
||||||
|
|||||||
@@ -4,12 +4,17 @@ package payments
|
|||||||
|
|
||||||
import "github.com/stripe/stripe-go/v74"
|
import "github.com/stripe/stripe-go/v74"
|
||||||
|
|
||||||
|
// Available is a constant used to indicate that Stripe support is available.
|
||||||
|
// It can be disabled with the 'nopayments' build tag.
|
||||||
const Available = true
|
const Available = true
|
||||||
|
|
||||||
|
// SubscriptionStatus is an alias for stripe.SubscriptionStatus
|
||||||
type SubscriptionStatus stripe.SubscriptionStatus
|
type SubscriptionStatus stripe.SubscriptionStatus
|
||||||
|
|
||||||
|
// PriceRecurringInterval is an alias for stripe.PriceRecurringInterval
|
||||||
type PriceRecurringInterval stripe.PriceRecurringInterval
|
type PriceRecurringInterval stripe.PriceRecurringInterval
|
||||||
|
|
||||||
|
// Setup sets the Stripe secret key and disables telemetry
|
||||||
func Setup(stripeSecretKey string) {
|
func Setup(stripeSecretKey string) {
|
||||||
stripe.EnableTelemetry = false // Whoa!
|
stripe.EnableTelemetry = false // Whoa!
|
||||||
stripe.Key = stripeSecretKey
|
stripe.Key = stripeSecretKey
|
||||||
|
|||||||
@@ -2,12 +2,17 @@
|
|||||||
|
|
||||||
package payments
|
package payments
|
||||||
|
|
||||||
|
// Available is a constant used to indicate that Stripe support is available.
|
||||||
|
// It can be disabled with the 'nopayments' build tag.
|
||||||
const Available = false
|
const Available = false
|
||||||
|
|
||||||
|
// SubscriptionStatus is a dummy type
|
||||||
type SubscriptionStatus string
|
type SubscriptionStatus string
|
||||||
|
|
||||||
|
// PriceRecurringInterval is dummy type
|
||||||
type PriceRecurringInterval string
|
type PriceRecurringInterval string
|
||||||
|
|
||||||
|
// Setup is a dummy type
|
||||||
func Setup(stripeSecretKey string) {
|
func Setup(stripeSecretKey string) {
|
||||||
// Nothing to see here
|
// Nothing to see here
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build !nofirebase
|
||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -14,6 +16,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// FirebaseAvailable is a constant used to indicate that Firebase support is available.
|
||||||
|
// It can be disabled with the 'nofirebase' build tag.
|
||||||
|
FirebaseAvailable = true
|
||||||
|
|
||||||
fcmMessageLimit = 4000
|
fcmMessageLimit = 4000
|
||||||
fcmApnsBodyMessageLimit = 100
|
fcmApnsBodyMessageLimit = 100
|
||||||
)
|
)
|
||||||
@@ -73,7 +79,7 @@ type firebaseSenderImpl struct {
|
|||||||
client *messaging.Client
|
client *messaging.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFirebaseSender(credentialsFile string) (*firebaseSenderImpl, error) {
|
func newFirebaseSender(credentialsFile string) (firebaseSender, error) {
|
||||||
fb, err := firebase.NewApp(context.Background(), nil, option.WithCredentialsFile(credentialsFile))
|
fb, err := firebase.NewApp(context.Background(), nil, option.WithCredentialsFile(credentialsFile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
38
server/server_firebase_dummy.go
Normal file
38
server/server_firebase_dummy.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
//go:build nofirebase
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"heckel.io/ntfy/v2/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// FirebaseAvailable is a constant used to indicate that Firebase support is available.
|
||||||
|
// It can be disabled with the 'nofirebase' build tag.
|
||||||
|
FirebaseAvailable = false
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errFirebaseNotAvailable = errors.New("Firebase not available")
|
||||||
|
errFirebaseTemporarilyBanned = errors.New("visitor temporarily banned from using Firebase")
|
||||||
|
)
|
||||||
|
|
||||||
|
type firebaseClient struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *firebaseClient) Send(v *visitor, m *message) error {
|
||||||
|
return errFirebaseNotAvailable
|
||||||
|
}
|
||||||
|
|
||||||
|
type firebaseSender interface {
|
||||||
|
Send(m string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFirebaseClient(sender firebaseSender, auther user.Auther) *firebaseClient {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFirebaseSender(credentialsFile string) (firebaseSender, error) {
|
||||||
|
return nil, errFirebaseNotAvailable
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build !nofirebase
|
||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
Reference in New Issue
Block a user