Log even more garbage
Test / test (push) Failing after 54s
Details
Test / test (push) Failing after 54s
Details
This commit is contained in:
parent
3ff16c58b2
commit
121cc90de9
|
|
@ -100,51 +100,63 @@ export default function start(self: ServiceWorkerGlobalScope) {
|
||||||
})()
|
})()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
async function submitSubscription(
|
async function submitSubscription(
|
||||||
registration: ServiceWorkerRegistration,
|
registration: ServiceWorkerRegistration,
|
||||||
subscription: PushSubscription | null
|
subscription: PushSubscription | null
|
||||||
) {
|
) {
|
||||||
const db = database()
|
const db = database()
|
||||||
|
|
||||||
if (subscription === null) return
|
await sendMessage({
|
||||||
|
message: `Is subscription null? ${subscription === null}`,
|
||||||
|
})
|
||||||
|
|
||||||
const existingSubscriptionId = await db.subscriptions.get(1)
|
if (subscription === null) return
|
||||||
|
|
||||||
const applicationServerKey = urlB64ToUint8Array(pushPublicKey)
|
const existingSubscriptionId = await db.subscriptions.get(1)
|
||||||
const newSubscription = await registration.pushManager.subscribe({
|
|
||||||
userVisibleOnly: true,
|
|
||||||
applicationServerKey: applicationServerKey,
|
|
||||||
})
|
|
||||||
|
|
||||||
await (existingSubscriptionId === undefined
|
await sendMessage({
|
||||||
? postSubscription(newSubscription, db)
|
message: `Existing subscription ID ${existingSubscriptionId}`,
|
||||||
: putSubscription(newSubscription, existingSubscriptionId.subscriptionId))
|
})
|
||||||
|
|
||||||
return newSubscription
|
const applicationServerKey = urlB64ToUint8Array(pushPublicKey)
|
||||||
}
|
const newSubscription = await registration.pushManager.subscribe({
|
||||||
|
userVisibleOnly: true,
|
||||||
|
applicationServerKey: applicationServerKey,
|
||||||
|
})
|
||||||
|
|
||||||
async function postSubscription(
|
await (existingSubscriptionId === undefined
|
||||||
subscription: PushSubscription,
|
? postSubscription(newSubscription, db)
|
||||||
db: ReturnType<typeof database>
|
: putSubscription(newSubscription, existingSubscriptionId.subscriptionId))
|
||||||
) {
|
|
||||||
const response = await fetch(`${process.env.BASE_URL}/api/subscription/`, {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(subscription),
|
|
||||||
})
|
|
||||||
|
|
||||||
db.subscriptions.put({
|
return newSubscription
|
||||||
id: 1,
|
}
|
||||||
subscriptionId: (await response.json()).subscriptionId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function putSubscription(subscription: PushSubscription, id: number) {
|
async function postSubscription(
|
||||||
return fetch(`${process.env.BASE_URL}/api/subscription/${id}`, {
|
subscription: PushSubscription,
|
||||||
method: "PUT",
|
db: ReturnType<typeof database>
|
||||||
body: JSON.stringify(subscription),
|
) {
|
||||||
})
|
const response = await fetch(`${process.env.BASE_URL}/api/subscription/`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(subscription),
|
||||||
|
})
|
||||||
|
|
||||||
|
await sendMessage({
|
||||||
|
message: `Response status ${response.status}`,
|
||||||
|
})
|
||||||
|
|
||||||
|
db.subscriptions.put({
|
||||||
|
id: 1,
|
||||||
|
subscriptionId: (await response.json()).subscriptionId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function putSubscription(subscription: PushSubscription, id: number) {
|
||||||
|
return fetch(`${process.env.BASE_URL}/api/subscription/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(subscription),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function database() {
|
function database() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue