Skip to content

Commit 6729bdd

Browse files
refactor: improve readability by formatting long conditional statements in test-webpush.vue and webpush.ts
1 parent 2cf620b commit 6729bdd

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

app/pages/test-webpush.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const hasWebPushConfig = computed(() => {
3737
3838
// Browser support check
3939
const isSupported = computed(() => {
40-
if (typeof window === 'undefined') return false
40+
if (typeof window === 'undefined')
41+
return false
4142
return 'serviceWorker' in navigator && 'PushManager' in window && 'Notification' in window
4243
})
4344
@@ -91,7 +92,8 @@ async function fetchApps() {
9192
}
9293
9394
function initializeClient() {
94-
if (!selectedApp.value?.vapidPublicKey) return
95+
if (!selectedApp.value?.vapidPublicKey)
96+
return
9597
9698
nitroPingClient = new NitroPingClient({
9799
appId: selectedApp.value.id,
@@ -101,7 +103,8 @@ function initializeClient() {
101103
}
102104
103105
async function checkSubscription() {
104-
if (!isSupported.value || !nitroPingClient) return
106+
if (!isSupported.value || !nitroPingClient)
107+
return
105108
106109
try {
107110
const status = await nitroPingClient.getSubscriptionStatus()
@@ -114,7 +117,8 @@ async function checkSubscription() {
114117
}
115118
116119
async function subscribeToPush() {
117-
if (!isSupported.value || !nitroPingClient) return
120+
if (!isSupported.value || !nitroPingClient)
121+
return
118122
119123
isLoading.value = true
120124
error.value = ''
@@ -143,7 +147,8 @@ async function subscribeToPush() {
143147
}
144148
145149
async function unsubscribeFromPush() {
146-
if (!nitroPingClient) return
150+
if (!nitroPingClient)
151+
return
147152
148153
isLoading.value = true
149154
error.value = ''
@@ -171,7 +176,8 @@ async function unsubscribeFromPush() {
171176
}
172177
173178
async function sendTestNotification() {
174-
if (!isSubscribed.value || !selectedAppId.value) return
179+
if (!isSubscribed.value || !selectedAppId.value)
180+
return
175181
176182
isLoading.value = true
177183
error.value = ''

server/providers/webpush.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,32 @@ class WebPushProvider {
139139
const subscriberPublicKeyRaw = Buffer.from(subscription.keys.p256dh, 'base64url')
140140
// Reconstruct SPKI format for the subscriber's public key (P-256 SPKI header + raw key)
141141
const spkiHeader = Buffer.from([
142-
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01,
143-
0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00,
142+
0x30,
143+
0x59,
144+
0x30,
145+
0x13,
146+
0x06,
147+
0x07,
148+
0x2A,
149+
0x86,
150+
0x48,
151+
0xCE,
152+
0x3D,
153+
0x02,
154+
0x01,
155+
0x06,
156+
0x08,
157+
0x2A,
158+
0x86,
159+
0x48,
160+
0xCE,
161+
0x3D,
162+
0x03,
163+
0x01,
164+
0x07,
165+
0x03,
166+
0x42,
167+
0x00,
144168
])
145169
const subscriberSpki = Buffer.concat([spkiHeader, subscriberPublicKeyRaw])
146170
const subscriberPublicKeyObj = crypto.createPublicKey({ key: subscriberSpki, format: 'der', type: 'spki' })

0 commit comments

Comments
 (0)