0
0
Fork 0

Add endpoint to remove web push subscription (#32626)

This commit is contained in:
David Roetzel 2024-10-23 10:02:31 +02:00 committed by GitHub
parent d1b20ea8f7
commit 05f23df3b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 76 additions and 5 deletions

View file

@ -2,10 +2,11 @@
class Web::PushNotificationWorker
include Sidekiq::Worker
include RoutingHelper
sidekiq_options queue: 'push', retry: 5
TTL = 48.hours.to_s
TTL = 48.hours
URGENCY = 'normal'
def perform(subscription_id, notification_id)
@ -23,12 +24,13 @@ class Web::PushNotificationWorker
request.add_headers(
'Content-Type' => 'application/octet-stream',
'Ttl' => TTL,
'Ttl' => TTL.to_s,
'Urgency' => URGENCY,
'Content-Encoding' => 'aesgcm',
'Encryption' => "salt=#{Webpush.encode64(payload.fetch(:salt)).delete('=')}",
'Crypto-Key' => "dh=#{Webpush.encode64(payload.fetch(:server_public_key)).delete('=')};#{web_push_request.crypto_key_header}",
'Authorization' => web_push_request.authorization_header
'Authorization' => web_push_request.authorization_header,
'Unsubscribe-URL' => subscription_url
)
request.perform do |response|
@ -72,4 +74,8 @@ class Web::PushNotificationWorker
def request_pool
RequestPool.current
end
def subscription_url
api_web_push_subscription_url(id: @subscription.generate_token_for(:unsubscribe))
end
end