mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-09-05 03:21:26 +02:00
Minor changes
This commit is contained in:
parent
30a8f66db2
commit
020996ea04
7 changed files with 61 additions and 26 deletions
|
@ -146,8 +146,8 @@
|
|||
|
||||
# Web Push support (background notifications for browsers)
|
||||
#
|
||||
# If enabled, allows ntfy to receive push notifications, even when the ntfy web app is closed. When enabled, the user
|
||||
# can enable background notifications. Once enabled by the user, ntfy will forward published messages to the push
|
||||
# If enabled, allows ntfy to receive push notifications, even when the ntfy web app is closed. When enabled, users
|
||||
# can enable background notifications in the web app. Once enabled, ntfy will forward published messages to the push
|
||||
# endpoint, which will then forward it to the browser.
|
||||
#
|
||||
# You must configure all settings below to enable Web Push.
|
||||
|
|
|
@ -431,6 +431,41 @@ func TestAccount_Delete_Not_Allowed(t *testing.T) {
|
|||
require.Equal(t, 40026, toHTTPError(t, rr.Body.String()).Code)
|
||||
}
|
||||
|
||||
func TestAccount_Delete_Success_WithWebPush(t *testing.T) {
|
||||
conf := configureAuth(t, newTestConfigWithWebPush(t))
|
||||
conf.EnableSignup = true
|
||||
s := newTestServer(t, conf)
|
||||
|
||||
// Add account
|
||||
rr := request(t, s, "POST", "/v1/account", `{"username":"phil", "password":"mypass"}`, nil)
|
||||
require.Equal(t, 200, rr.Code)
|
||||
|
||||
// Add web push subscription
|
||||
rr = request(t, s, "POST", "/v1/webpush", payloadForTopics(t, []string{"mytopic"}, testWebPushEndpoint), map[string]string{
|
||||
"Authorization": util.BasicAuth("phil", "mypass"),
|
||||
})
|
||||
require.Equal(t, 200, rr.Code)
|
||||
|
||||
u, err := s.userManager.User("phil")
|
||||
require.Nil(t, err)
|
||||
|
||||
subs, err := s.webPush.SubscriptionsForTopic("mytopic")
|
||||
require.Nil(t, err)
|
||||
require.Len(t, subs, 1)
|
||||
require.Equal(t, u.ID, subs[0].UserID)
|
||||
|
||||
// Delete account
|
||||
rr = request(t, s, "DELETE", "/v1/account", `{"password":"mypass"}`, map[string]string{
|
||||
"Authorization": util.BasicAuth("phil", "mypass"),
|
||||
})
|
||||
require.Equal(t, 200, rr.Code)
|
||||
|
||||
// Make sure web push subscription was deleted
|
||||
subs, err = s.webPush.SubscriptionsForTopic("mytopic")
|
||||
require.Nil(t, err)
|
||||
require.Len(t, subs, 0)
|
||||
}
|
||||
|
||||
func TestAccount_Reservation_AddWithoutTierFails(t *testing.T) {
|
||||
conf := newTestConfigWithAuthFile(t)
|
||||
conf.EnableSignup = true
|
||||
|
|
|
@ -120,7 +120,6 @@ func (s *Server) pruneAndNotifyWebPushSubscriptionsInternal() error {
|
|||
}
|
||||
payload, err := json.Marshal(newWebPushSubscriptionExpiringPayload())
|
||||
if err != nil {
|
||||
log.Tag(tagWebPush).Err(err).Warn("Unable to marshal expiring payload")
|
||||
return err
|
||||
}
|
||||
warningSent := make([]*webPushSubscription, 0)
|
||||
|
@ -140,7 +139,14 @@ func (s *Server) pruneAndNotifyWebPushSubscriptionsInternal() error {
|
|||
|
||||
func (s *Server) sendWebPushNotification(sub *webPushSubscription, message []byte, contexters ...log.Contexter) error {
|
||||
log.Tag(tagWebPush).With(sub).With(contexters...).Debug("Sending web push message")
|
||||
resp, err := webpush.SendNotification(message, sub.ToSubscription(), &webpush.Options{
|
||||
payload := &webpush.Subscription{
|
||||
Endpoint: sub.Endpoint,
|
||||
Keys: webpush.Keys{
|
||||
Auth: sub.Auth,
|
||||
P256dh: sub.P256dh,
|
||||
},
|
||||
}
|
||||
resp, err := webpush.SendNotification(message, payload, &webpush.Options{
|
||||
Subscriber: s.config.WebPushEmailAddress,
|
||||
VAPIDPublicKey: s.config.WebPushPublicKey,
|
||||
VAPIDPrivateKey: s.config.WebPushPrivateKey,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"github.com/SherClockHolmes/webpush-go"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
@ -512,16 +511,6 @@ type webPushSubscription struct {
|
|||
UserID string
|
||||
}
|
||||
|
||||
func (w *webPushSubscription) ToSubscription() *webpush.Subscription {
|
||||
return &webpush.Subscription{
|
||||
Endpoint: w.Endpoint,
|
||||
Keys: webpush.Keys{
|
||||
Auth: w.Auth,
|
||||
P256dh: w.P256dh,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (w *webPushSubscription) Context() log.Context {
|
||||
return map[string]any{
|
||||
"web_push_subscription_id": w.ID,
|
||||
|
|
|
@ -63,8 +63,12 @@ const (
|
|||
WHERE st.topic = ?
|
||||
ORDER BY endpoint
|
||||
`
|
||||
selectWebPushSubscriptionsExpiringSoonQuery = `SELECT id, endpoint, key_auth, key_p256dh, user_id FROM subscription WHERE warned_at = 0 AND updated_at <= ?`
|
||||
insertWebPushSubscriptionQuery = `
|
||||
selectWebPushSubscriptionsExpiringSoonQuery = `
|
||||
SELECT id, endpoint, key_auth, key_p256dh, user_id
|
||||
FROM subscription
|
||||
WHERE warned_at = 0 AND updated_at <= ?
|
||||
`
|
||||
insertWebPushSubscriptionQuery = `
|
||||
INSERT INTO subscription (id, endpoint, key_auth, key_p256dh, user_id, subscriber_ip, updated_at, warned_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT (endpoint)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue