Explorar el Código

Add build tags for Firebase

binwiederhier hace 6 meses
padre
commit
99a2ca8802

+ 2 - 0
cmd/serve.go

@@ -279,6 +279,8 @@ func execServe(c *cli.Context) error {
 	// Check values
 	if firebaseKeyFile != "" && !util.FileExists(firebaseKeyFile) {
 		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 == "") {
 		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 {

+ 5 - 0
payments/payments.go

@@ -4,12 +4,17 @@ package payments
 
 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
 
+// SubscriptionStatus is an alias for stripe.SubscriptionStatus
 type SubscriptionStatus stripe.SubscriptionStatus
 
+// PriceRecurringInterval is an alias for stripe.PriceRecurringInterval
 type PriceRecurringInterval stripe.PriceRecurringInterval
 
+// Setup sets the Stripe secret key and disables telemetry
 func Setup(stripeSecretKey string) {
 	stripe.EnableTelemetry = false // Whoa!
 	stripe.Key = stripeSecretKey

+ 5 - 0
payments/payments_dummy.go

@@ -2,12 +2,17 @@
 
 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
 
+// SubscriptionStatus is a dummy type
 type SubscriptionStatus string
 
+// PriceRecurringInterval is dummy type
 type PriceRecurringInterval string
 
+// Setup is a dummy type
 func Setup(stripeSecretKey string) {
 	// Nothing to see here
 }

+ 7 - 1
server/server_firebase.go

@@ -1,3 +1,5 @@
+//go:build !nofirebase
+
 package server
 
 import (
@@ -14,6 +16,10 @@ import (
 )
 
 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
 	fcmApnsBodyMessageLimit = 100
 )
@@ -73,7 +79,7 @@ type firebaseSenderImpl struct {
 	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))
 	if err != nil {
 		return nil, err

+ 38 - 0
server/server_firebase_dummy.go

@@ -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
+}

+ 2 - 0
server/server_firebase_test.go

@@ -1,3 +1,5 @@
+//go:build !nofirebase
+
 package server
 
 import (